Hi all,

I need to rotate image with transparent background. I am using PHP5.1 and GD2.1.

I am creating a gif after rotation. Also tried to create png. but not getting transparent background. Also sometimes getting black background.

can any one help on this.

Thanks in advance

7 Years
Discussion Span
Last Post by beeerlover

Fist off a few questions before I start helping you with you code:

  1. Do you have any code yet? If so may we see it?
  2. What file type do you want to save as? (You mention both PNG and GIF in your post)
  3. Do you want to rotate the image or do you want an animation of the image rotating? (GIF's can contain short animation and you mentioned them)
  4. And finally, if you only want a rotation...do you know how many degress? (It's alright to if that will be determined by user input.

If you could answer these, I will have a better understanding of what you are doing and be able to help you with your problems.


Rotate Image - I assume you mean randomly display an image from a list of images as opposed to actually rotating the image 90 degrees or something, right? (If not we can help with that too).

In its simplest form, random image with php:

$ri = array();

$ri[] = '<img src="image1.gif" />';

$ri[] = '<img src="image2.gif" />';

$ri[] = '<img src="image3.gif" />';

$ri[] = '<img src="image4.gif" />';

$num = rand(0,(count($ri)-1));
echo $ri[$num];

You can add or subtract as many images as you want to that code, you can add html markup such as alt text, title tag, hyperlink, ect. You can literally put any html in between the single quotes as you like.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.