$image = \"[...]\"; //binary string containing PNG image
$file = fopen(\'image.tmp\', \'wb\');
fputs($file, $image);
fclose($file);
$image = new Imagick(\'PNG:image.
Another way to convert transparent png to jpg, as mentioned in Imagick::flattenImages:
$im = new Imagick('image.png');
$im->setImageBackgroundColor('white');
$im->flattenImages(); // This does not do anything.
$im = $im->flattenImages(); // Use this instead.
$im->setImageFormat('jpg');
$im->writeImage('image.jpg');
As time moves on, flattenImages() has been deprecated.
Instead of the line above use:
$im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);