Image Resampling Not Working
Posted: 2010-02-22T18:29:33-07:00
I'm currently doing image resizing and resampling with PNGs. I've noticed that for some PNGs (possibly when they contain transparency) that the image resizing works but the resampling fails without throwing any error. This means I'm left with a 72dpi image instead of a 300dpi image which I need for embedding within a PDF. Does anyone have any ideas on this? I appreciate any help.
Here is the code:
System info:
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
Imagick Info:
imagick module: enabled
imagick module version: 2.2.2
imagick classes: Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version: ImageMagick 6.5.5-7 2010-01-29 Q16 http://www.imagemagick.org
ImageMagick copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
ImageMagick release date: 2010-01-29
ImageMagick Number of supported formats: 194
ImageMagick Supported formats: A, AI, ART, ARW, AVI, AVS, B, BGR, BIE, BMP, BMP2, BMP3, BRG, C, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DNG, DPS, DPX, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FAX, FITS, FPX, FRACTAL, FTS, G, G3, GBR, GIF, GIF87, GRADIENT, GRAY, GRB, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, INFO, INLINE, IPL, JBG, JBIG, JNG, JP2, JPC, JPEG, JPG, JPX, K, K25, KDC, LABEL, M, M2V, M4V, MAP, MAT, MATTE, MIFF, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NULL, O, ORF, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RBG, RGB, RGBA, RGBO, RLA, RLE, SCR, SCT, SFW, SGI, SHTML, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UIL, UYVY, VDA, VICAR, VID, VIFF, VST, WBMP, WMV, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YCbCr, YCbCrA, YUV
Directive Local Value: Master Value
imagick.locale_fix: 0 0
imagick.progress_monitor: 0 0
Here is the code:
Code: Select all
$image_file = new Imagick("image.png");
$image_file->setImageColorspace(imagick::COLORSPACE_TRANSPARENT);
$image_file->setImageOpacity(1.0);
$image_file->readImage("image.png");
$icc_profile = file_get_contents('AdobeRGB1998.icc');
$image_file->profileImage('icc', $icc_profile);
if (!$image_file->resampleImage(300, 300, 0, 1) || !$image_file->resizeImage(140 * (300/72), 140 * (300/72), 0, 1)) {
// report error
}
else {
$image_file->writeImage("image.png");
}
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
Imagick Info:
imagick module: enabled
imagick module version: 2.2.2
imagick classes: Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version: ImageMagick 6.5.5-7 2010-01-29 Q16 http://www.imagemagick.org
ImageMagick copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
ImageMagick release date: 2010-01-29
ImageMagick Number of supported formats: 194
ImageMagick Supported formats: A, AI, ART, ARW, AVI, AVS, B, BGR, BIE, BMP, BMP2, BMP3, BRG, C, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DNG, DPS, DPX, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FAX, FITS, FPX, FRACTAL, FTS, G, G3, GBR, GIF, GIF87, GRADIENT, GRAY, GRB, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, INFO, INLINE, IPL, JBG, JBIG, JNG, JP2, JPC, JPEG, JPG, JPX, K, K25, KDC, LABEL, M, M2V, M4V, MAP, MAT, MATTE, MIFF, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NULL, O, ORF, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RBG, RGB, RGBA, RGBO, RLA, RLE, SCR, SCT, SFW, SGI, SHTML, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UIL, UYVY, VDA, VICAR, VID, VIFF, VST, WBMP, WMV, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YCbCr, YCbCrA, YUV
Directive Local Value: Master Value
imagick.locale_fix: 0 0
imagick.progress_monitor: 0 0