Transparency removed

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

Transparency removed

Post by snibgo »

The current version of IM for Windows, 6.8.2-0, seems to be removing transparency.

Code: Select all

"%IMG682%convert" -size 100x100 xc:none -fill Red -draw "rectangle 20,20 80,80" t.png
"%IMG682%convert" t.png t2.png
t2.png has black where t.png wa transparent.

See also viewtopic.php?f=1&t=22715&p=94877#p94877, where the OP reports another problem "seems to be adding some opaque layer on top of the image" that I haven't investigated.
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: Transparency removed

Post by glennrp »

Verified with IM-6.8.2-2 on Ubuntu. It seems to be a bug in the PNG reader. It is seeing the tRNS chunk but apparently not applying it correctly.

extract from log with identify -verbose -debug coder -log %e t1.png:
  • Reading PNG tRNS chunk.
    Reading PNG PLTE chunk: number_colors: 2.
    Reading PNG IDAT chunk(s)
    Converting PNG pixels to pixel packets
    Converting grayscale pixels to pixel packets
    No transparent pixel was found <=== this is wrong.
I tried making t1.png a PNG8 but got the same wrong result.
It works properly if t1.png is a PNG32.

The bug appears to be a regression that occurred in version 6.8.1-10. (-9 works).
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Transparency removed

Post by glennrp »

Fixed in SVN revision 10888 (to be IM-6.8.2-3).
jflux
Posts: 8
Joined: 2013-02-06T22:38:21-07:00
Authentication code: 6789

Re: Transparency removed

Post by jflux »

Noticing a similar problem when filtering using functions that are calling StatisticImage.

MagickMedianFilterImage
MagickReduceNoiseImage

both replace the Transparency with solids and a black background, no longer appears to process the alpha data, looks like it strips the alpha then processes.

Attempted with 6.8.2-4 , 6.7.7, and a few others, all appear to be broken in the same way. (everything else works correctly, just no transparency using median / filtering commands).. Prior versions will no longer install do to zlib updates.

These functions work perfectly on our production machine running an old 6.6.3 .

Noticed an old message board reporting the exact same issue dating back to August 2011 starting with v6.7. Was hoping it had been fixed with this update, but still broken.

I've simulated a fix by splitting the data, post processing the bg to transparent and cataloging colors, then faking the alphas with color replacements, a real mess that still leaves the alphas out of the filter equation.. A shame this is broken as it has been one of the more powerful features in imagemagic and on-the-fly processing.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Transparency removed

Post by magick »

Alpha works for us. From the command-line, add -channel RGBA before the -median option. From MagickCore, call StatisticImageChannel() and ensure alpha is set for the channel parameter.
jflux
Posts: 8
Joined: 2013-02-06T22:38:21-07:00
Authentication code: 6789

Re: Transparency removed

Post by jflux »

Thanks for info.
I know it's capable of preserving the alpha thru command line, but for whatever reason the magickwand function no longer appears to do so.

This is an existing project (DOD image processing algorithm) that we run thru a php / magickwand setup. Everything attempted thru magickwand and imagick is in php and works, except starting with version 6.7 filters loose the alpha. Prior to 6.7 no problems at all.

A series of color replacements and alpha parameters are applied using magickwand (MagickOpaquePaintImage, and MagickTransparentPaintImage), then MagickMedianFilterImage is called.

Alpha is generated by the magickwand functions and also exists in the base image, (and works fine until the filter drops it). Does imagemagick no longer pass the alpha set directly from it's own code when running the filter? ( are you saying -channel RGBA now get's lost / is no longer identified from the passed wand and must be re-added right after it's been set?)

Found no indication of a problem in php's magickwand, as it simply calls the function and passes the wand and radius (edited the source to make sure that's all it does), but I'll double check to see if it may need tweaking.

Still looks like an issue with magickwand/imagemagick considering the behavior has "changed" from an expected output, to an output with missing alphas that overwrites the underlying composite with solid black. Command line options may patch the issue, but prior to 6.7 such options were not needed, and it's not needed on any of the other functions we are calling, just the median filter?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Transparency removed

Post by fmw42 »

In IM 6.8.2.5 Mac OSX Snow Leopard

# create transparent png (works fine)
convert logo: -transparent white logot.png

# apply median filter (loses transparency)
convert logot.png -statistic median 3x3 logot_med3.png

# apply median filter (maintains transparency)
convert logot.png -alpha on -statistic median 3x3 logot_med3.png

# apply median filter (maintains transparency)
convert logot.png -channel rgba -statistic median 3x3 logot_med3.png


In IM 6.6.0.10, I ran the old -median function and it failed to retain the alpha channel with or without -channel rgba
convert logot.png -median 1 logot_med3.png

Have I misunderstood what command you are trying to do or what image you might have tried it on?
jflux
Posts: 8
Joined: 2013-02-06T22:38:21-07:00
Authentication code: 6789

Re: Transparency removed

Post by jflux »

The command line options and non PHP scripts appear to work here as well.

Appears the problem is specific to Magickwand for PHP. The Magickwand for PHP devs likely need to figure this one out. I can't find an option in their source that passes alpha to the filter, so if it's now required, it's likely missing.

Seriously thanks for the help,

I'll shift this to the Magickwand For PHP forum since it appears unrelated to the OP's problem.
Post Reply