Php imagick convert PNG to jpg?

You can use setBackgroundColor to set the default background color to something else than black. The PNG transparency will be replaced by the background color when saving to JPG.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

$image = "..."; //binary string containing PNG image $file = fopen('image. Tmp', 'wb'); fputs($file, $image); fclose($file); $image = new Imagick('PNG:image. Tmp'); $image->thumbnailImage($width, $height); $image->setImageFormat('jpg'); $image->setCompressionQuality(97); $image->writeImage('image.

Jpg'); The above doesn't work and gives me a black image for this image. When doing instead ... $image->setImageFormat('png'); $image->setCompressionQuality(97); $image->writeImage('image. Png'); all is fine again.

I think it has to do something with transparent background, which isn't available in JPG format. Can anyone help to solve this (imagick isn't documented very well, so I don't know how to help myself). Php png transparent jpg imagick link|improve this question asked Jul 7 '11 at 12:39rabudde2,838215 82% accept rate.

You can use setBackgroundColor to set the default background color to something else than black. The PNG transparency will be replaced by the background color when saving to JPG. Edit: Use it like so: $img->setBackgroundColor(new ImagickPixel('#FFFFFF')).

Found a solution: $white=new Imagick(); $white->newImage($width, $height, "white"); $white->compositeimage($image, Imagick::COMPOSITE_OVER, 0, 0); $white->setImageFormat('jpg'); $white->writeImage('image. Jpg').

Try adding $image->setBackgroundColor(0xFFFFFF); after $image = new Imagick('PNG:image. Tmp').

PHP Fatal error: Uncaught exception 'ImagickException' with message 'Invalid parameter provided', using '#ffffff' instead doesn't result in a failure but doesn't help also. SetImageBackgroundColor doesn't work too – rabudde Jul 7 '11 at 12:59.

I don't know if this will be beneficial to you, but check out this wrapper class for imagemagick called phmagick francodacosta.com/phmagick.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions