Page 1 of 1

PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-14T17:14:00-07:00
by merv
From inside a bash script:

Code: Select all

convert /tmp/temp.png -alpha activate -channel RGBA -background "rgba(0,0,0,0.0)" -flop /tmp/temp2.png
I'm no expert but it seems to me that this is WAY TOO MUCH to just flop a transparent PNG without scrooing the transparency pooch.

I've tried a bunch of variants of the above, and now I've run into something TOTALLY WHACK with PHP ImageMagick extension.

Input 1: Image
Output: Image

Given this PHP script:

Code: Select all

 function thumbnailImage($imagePath) {
  $im = new Imagick();
  $im->setBackgroundColor(new ImagickPixel('transparent'));
  $im->readImage(realpath($imagePath));
  $dim=$im->getImageGeometry();
  if ( !isset($_GET['wh']) ) $wh=100; $wh=intval($_GET['wh']);
  if ( $wh <= 0 ) $wh=100;
//  $aspect=floatval($dim['width'])/floatval($dim['height']);
//  $inverse_aspect=floatval($dim['height'])/floatval($dim['width']);
  $width=$wh;
  $height=$wh;
  $im->setImageFormat("png32");
  $im->thumbnailImage($width,$height, true, true);
  header("Content-Type: image/png");
  echo $im;
 }
 if ( isset($_GET['src']) ) {
  try {
   @thumbnailImage(urldecode($_GET['src']));
  } catch ( Exception $e ) {}
 }
 
Input appears transparent.
Output appears with black background.

What gives? :(

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-14T17:19:07-07:00
by fmw42
This works just fine for me in IM 6.9.2.4 Q16 Mac OSX with libpng 1.6.12_0

Code: Select all

convert temp.png -flop temp2.png
What platform are you on and what version of Imagemagick and what version of libpng

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-14T17:24:36-07:00
by snibgo
merv wrote:-alpha activate -channel RGBA -background "rgba(0,0,0,0.0)"
Why do you need this? How does it affect the "flop" operation?

If I do ...

Code: Select all

convert temp.png -flop temp2.png
... it works fine. ImageMagick v6.9.1-6. What version are you on?

Or perhaps you are using IMagick, which isn't ImageMagick.

I don't do PHP, and can't help you there.

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-14T17:26:22-07:00
by merv

Code: Select all

$ convert --version
Version: ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
From PHP Info:

Code: Select all

imagick
imagick module	enabled
imagick module version 	3.1.0RC1
imagick classes 	Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version 	ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org
ImageMagick copyright 	Copyright (C) 1999-2011 ImageMagick Studio LLC
ImageMagick release date 	2014-03-06
ImageMagick number of supported formats: 	206
ImageMagick supported formats 	3FR, A, AAI, AI, ART, ARW, AVI, AVS, B, BGR, BGRA, BMP, BMP2, BMP3, BRF, C, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FITS, FRACTAL, FTS, G, G3, GIF, GIF87, GRADIENT, GRAY, GROUP4, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, INFO, INLINE, IPL, ISOBRL, J2C, JNG, JP2, JPC, JPEG, JPG, JPX, K, K25, KDC, LABEL, M, M2V, M4V, MAC, 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, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, 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, UBRL, UIL, UYVY, VDA, VICAR, VID, VIFF, VST, WBMP, WMF, WMV, WMZ, 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

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-14T17:45:10-07:00
by snibgo
Ah, 6.6.9-7, about 219 versions ago. I suggest you upgrade.

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-14T18:08:29-07:00
by glennrp
merv wrote:

Code: Select all

$ convert --version
Version: ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Note that the date shown (2014-03-06) is misleading; it's the date
that your copy of ImageMagick was installed. Version 6.6.9-7 was released
about three years earlier, on 2011-04-30.

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-15T06:14:51-07:00
by merv
How can I upgrade this? This was the package available on PHP

Re: PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Posted: 2015-10-15T09:05:47-07:00
by fmw42
What is the version of Imagick? Can your or your ISP install a newer version?