tags:

views:

194

answers:

2

Hello people, Since last 2 days, I was trying to add transperancy to the background after rotating an image using imagerotate() PHP-GD function.

But, to my great disappointment, it's not working at all.

It's just giving out a black background behind it.

Here's my code -


$patchImageS    =   'image.png'; // the image to be patched over the final bg
$patchImage =   imagecreatefrompng($patchImageS); // resource of image to be patched
$patchImage     =   imagerotate($patchImage, 23, 0, 0);
imagepng($patchImage,'tt.png');

I tried to change the parameters being passed in function to

imagerotate($patchImage, 23, 5, 0);

imagerotate($patchImage, 23, 0, 5);

Any help would be highly appreciated.

+1  A: 

look for imagesavealpha() in the php-documentation - i think this is what you are looking for.

EDIT: here's an example:

$png = imagecreatefrompng('./alphachannel_example.png');

// Do required operations
$png = imagerotate($png, 23, 0, 0);

// Turn off alpha blending and set alpha flag
imagealphablending($png, false);
imagesavealpha($png, true);

// Output image to browser
header('Content-Type: image/png');

imagepng($png);
imagedestroy($png);
oezi
can you provide any example?
KPL
okay .Thanks for it ... i ll try it out.But will it work irrespective of the image extension ? Or we can always convert images to PNG .
KPL
i tried that ... but it still gives a white background and not a transperant one ...
KPL
A: 

There is a bug that when doing imagerotate() on png images for greater than 45 degrees, the transparency of the image is lost. How fun is that?

Nan