0

While developping color-extractor I stumbled across a quirk with Imagick. I confirmed the issue with a single black transparent pixel image. Under Gimp this black is shown as 75% opaque so I guess its alpha/transparency is 25%.

When I run getColorValue(\Imagick::COLOR_OPACITY) I get roughly 0.25 whereas I get about 0.75 with getColorValue(\Imagick::COLOR_ALPHA) so the exact opposite of what I expected.

Is this an issue about Imagick (I'm using php-imagick 3.4.3-1 and ImageMagick 6.9.7-9) or am I inverting concepts of opacity and transparency?

MatTheCat
  • 18,071
  • 6
  • 54
  • 69

1 Answers1

0

Not a quirk, but by design. For the most part, opacity & alpha share the same data channel, and the context of the image format / coder implements the correct value. And I stress context is key.

Is this an issue about Imagick [..] or am I inverting concepts of opacity and transparency?

Let's take a look at how the two are implemented.

PixelGetOpacityQuantum

return(ClampToQuantum(wand->pixel.opacity));

PixelGetAlphaQuantum

return(QuantumRange-ClampToQuantum(wand->pixel.opacity));

As you can see, both return the same data bonded between 0 and Quantum limit.

The PixelGetOpacityQuantum returns the exact data-value, but PixelGetAlphaQuantum adjusts/inverts to what we would expect in popular color formats/specs. It's all context!

emcconville
  • 23,800
  • 4
  • 50
  • 66
  • I know opacity and transparency are inferred from a unique value but it seems Imagick returns opacity instead of transparency and vice-versa, that is my issue. – MatTheCat Feb 24 '17 at 17:48
  • In fact, ImageMagick version 7.x.x is different from ImageMagick 6.x.x in this regard. "We support alpha now, previously opacity" according to http://imagemagick.org/script/porting.php – Glenn Randers-Pehrson Feb 25 '17 at 16:44
  • I guess this could answer my question but I don't really get the meaning of the sentence. – MatTheCat Feb 25 '17 at 19:31
  • Correct @GlennRanders-Pehrson ! IM7 focuses on pixel traits, and alpha & opacity are isolated from each other. – emcconville Feb 25 '17 at 20:12