Resize and change DPI of image and preserve transparency
Posted: 2010-02-15T13:15:53-07:00
I'm having trouble using IMagick to resize images and change their DPI while retaining their transparency. I have tried with both PNGs and GIFs. For PNGs the transparency turns black and for GIFs the transparency turns white. This happens whether I just do the resize or just change the DPI setting. Details are as follows
ImageMagick 6.5.5-7 2010-01-29 Q16
PHP 5.2.10 with Suhosin-Patch 0.9.7 (cli) (built: Nov 16 2009 20:12:44)
FreeBSD 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009 amd64
Code is as follows:
ImageMagick 6.5.5-7 2010-01-29 Q16
PHP 5.2.10 with Suhosin-Patch 0.9.7 (cli) (built: Nov 16 2009 20:12:44)
FreeBSD 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009 amd64
Code is as follows:
Code: Select all
$image_file = new Imagick(file_directory_path() . "/image.gif");
$image_file->setImageOpacity(1.0);
if (!$image_file->resampleImage(300, 300, 0, 1) || !$image_file->resizeImage(70 * (300/72), 70 * (300/72), 0, 1)) {
#Error out
}
else {
$image_file->writeImage(file_directory_path() . "/image.gif");
}