detecting transparency of PNG file with matte() now fails

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
rajpaul
Posts: 3
Joined: 2012-11-23T14:52:49-07:00
Authentication code: 6789
Location: Toronto

detecting transparency of PNG file with matte() now fails

Post by rajpaul »

Hello all,

I have a project that is used to generate thumbnails and previews of various image types using the IM library. I had been using the ImageMagick library version 6.5.9. With that version, I could detect the presence of a transparency layer in a certain PNG file I have using the Magick++ Image class method matte(). It would return true for this file.

I needed to perform this detection in order to know when to use the "-flatten" feature to compose a thumbnail of the image on a white background. All was fine.

When I updated the underlying ImageMagick library to 6.7.9 the detection now fails. The matte() method used on the Image object after loading this source image file now returns false for the same file. The type() method returns MagickCore::TrueColorType. But when I use the "identify -verbose" command line tool from IM 6.7.6 I get the following output:

Code: Select all

  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 792x504+0+0
  Resolution: 28.35x28.35
  Print size: 27.9365x17.7778
  Units: PixelsPerCentimeter
  Type: TrueColorMatte
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 93.8249 (0.367941)
      standard deviation: 104.48 (0.409726)
      kurtosis: -1.25472
      skewness: 0.703069
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 96.0525 (0.376677)
      standard deviation: 104.367 (0.409282)
      kurtosis: -1.30609
      skewness: 0.656662
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 103.821 (0.407141)
      standard deviation: 104.817 (0.411046)
      kurtosis: -1.47573
      skewness: 0.491882
    Alpha:
      min: 0 (0)
      max: 255 (1)
      mean: 105.996 (0.415672)
      standard deviation: 119.074 (0.466956)
      kurtosis: -1.79443
      skewness: -0.371703
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 110.675 (0.434022)
      standard deviation: 108.367 (0.424969)
      kurtosis: -1.57012
      skewness: 0.375226
  Alpha: srgba(255,255,255,0)   #FFFFFF00
  Rendering intent: Perceptual
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.63999,0.33001)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.05999)
    white point: (0.31269,0.32899)
  Interlace: None
  Background color: white
  Border color: srgba(223,223,223,1)
  Matte color: grey74
  Transparent color: none
  Compose: Over
  Page geometry: 792x504+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
...
Is the change in the response from the matte() function a likely bug? Is there some other way to find out if there is a transparency layer?

Thanks.
Regards,
-Rajpaul
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: detecting transparency of PNG file with matte() now fail

Post by glennrp »

Several bugs in the PNG decoder have been fixed since 6.7.9-0 but I think they all relate to grayscale PNGs.
If you don't mind, please try 6.8.0-9, or post the PNG somewhere that we can download it, or send the PNG to
glennrp at imagemagick.org and I'll run some diagnostics on it.
rajpaul
Posts: 3
Joined: 2012-11-23T14:52:49-07:00
Authentication code: 6789
Location: Toronto

Re: detecting transparency of PNG file with matte() now fail

Post by rajpaul »

I tried with ImageMagick 6.8.1-9 and still receive the same results with the file I am working with.
I will send a sample file to glennrp's email.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: detecting transparency of PNG file with matte() now fail

Post by glennrp »

I received the file, and "identify" and other programs report that it
has transparency but not much. Alpha ranges from 0.996 to 1.000.
  • Alpha:
    min: 254 (0.996078)
    max: 255 (1)
    mean: 254.991 (0.999965)
I don't know why image->matte is not being reported properly for you.
Post Reply