PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
merv
Posts: 6
Joined: 2013-04-12T09:46:23-07:00
Authentication code: 6789

PHP ImageMagick, WTF Inconsistency using convert and PNG transparency

Post 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? :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
merv
Posts: 6
Joined: 2013-04-12T09:46:23-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Ah, 6.6.9-7, about 219 versions ago. I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post 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.
merv
Posts: 6
Joined: 2013-04-12T09:46:23-07:00
Authentication code: 6789

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

Post by merv »

How can I upgrade this? This was the package available on PHP
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

What is the version of Imagick? Can your or your ISP install a newer version?
Post Reply