Page 1 of 1

PNG to JPEG, transparent background converts to black

Posted: 2010-05-06T13:14:17-07:00
by pezz
When saving a PNG as JPEG by using $im->setimageformat('jpeg'), the resulting saved image has the transparent background replaced with a black background.

Is there any way to change the colour of this background?

Tried a lot of functions to no avail, setimagebackground(), setimagemattecolor().. Hope someone can help me :)

Re: PNG to JPEG, transparent background converts to black

Posted: 2010-05-06T13:38:25-07:00
by pezz
Nevermind, got it.

Code: Select all

$im->PaintOpaqueImage ('black', 'white', 50);

Re: PNG to JPEG, transparent background converts to black

Posted: 2010-05-06T14:00:43-07:00
by pezz
Another method was to put the PNG image data on top of a new, blank, white $im object:

Code: Select all

$im2 = new imagick();
$im2->newImage($im->getImageWidth(),$im->getImageheight(),'white','jpeg');
$im2->compositeimage($im,imagick::COMPOSITE_DEFAULT,0,0);