php将PNG转换为jpg

将图像从PNG转换为JPEG时,如何使用ImageMagick(带有php扩展名)将透明背景设置为白色?

[php]
$image = new IMagick('image.png');

$flattened = new IMagick();
$flattened->newImage($image->getImageWidth(), $image->getImageHeight(), new ImagickPixel("white"));

$flattened->compositeImage($image, imagick::COMPOSITE_OVER, 0, 0);

$flattened->setImageFormat("jpg");
$flattened->writeImage('image.jpg');

$image->clear();
$image->destroy();
$flattened->clear();
$flattened->destroy();
[/php]

阅读剩余
THE END