views:

209

answers:

2

How to rotate an image with PHP, any degree, without having the filled space? For instance, if I rotate an image 10 degrees, the image rotates fine but the container around (square) gets filled with black. Is it possible to get rid of this, when for example merging 2 images?

+2  A: 

You can set the background color in imagerotate as the third parameter.

I'm not quite sure what you are asking for otherwise. If you rotate an image, it has to remain a rectangle parallel to the axises. Therefore the image "container" is resized to fit the now rotated image.

St. John Johnson
+1  A: 

Try one of the GD/image alpha functions to make the background colour transparent:

$newImg = imagecolorallocate($image, 255, 255, 255, 127);

As john mentions though there will be a background colour, so you will have to make it transparent. the last parameter '127' represents complete transparency with 0 representing opaque. Check out php manual

...and make sure you're saving it as a png!

kalpaitch