Page 1 of 1

unclear about -alpha on with IM 6.4.3-8

Posted: 2008-09-23T15:29:46-07:00
by fmw42
The documentation says:

"On or Activate Enable the images use of transparency. If transparency data did not exist, allocate the data and set to opaque. If the image previously had transparency data, the data is again enable as it was when turned off."

Thus if I create a gradient, use -alpha copy to copy the gradient to the alpha channel, then turn off the alpha and then turn it on, I would expect the alpha channel to show the gradient again. But it is fully opaque, just the same as using -alpha set or -alpha opaque.

convert -size 100x100 gradient: grad.png
convert grad.png -alpha copy grad_acopy.png
convert grad_acopy.png -alpha off grad_acopy_aoff.png
convert grad_acopy_aoff.png -alpha on grad_acopy_aoff_aon.png
convert grad_acopy_aoff_aon.png -verbose info:

alpha:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: -0 (-0)


Am I misunderstanding this, since each command is on a separate command line?

Whereas, this works as one command line:

convert -size 100x100 gradient: -alpha copy -alpha off -alpha on grad_acopy_aoff_aon.png
convert grad_acopy_aoff_aon.png -verbose info:

alpha:
min: 0 (0)
max: 65535 (1)
mean: 32767.5 (0.5)
standard deviation: 19108.4 (0.291576)


But then, I don't understand why someone would want to do the latter --- turn it off, then on, all in the same command line.

Thus why is there a need for a difference between -alpha on/activate and -alpha set? (Not that extra options are bad)

Re: unclear about -alpha on with IM 6.4.3-8

Posted: 2008-09-23T16:46:27-07:00
by anthony
I would expect the alpha channel to show the gradient again.
In IM examples on this I also add...
Be warned that saving the image with the transparency data turned off, will not save any transparency data to the image file format, and it will be lost. Also not all image file formats handle transparency data (such as JPEG), or has limited handling (such as GIF).
On the other hand if you did...

convert grad_acopy.png -alpha off -write grad_acopy_aoff.png \
-alpha on grad_acopy_aoff_aon.png

then "grad_acopy_aoff.png" will be opaque (no transparency)
but "grad_acopy_aoff_aon.png" will look exactly like "grad_acopy.png".

It is a 'in-memory' boolean switch that just enabled or disables the use of alpha data. If 'off' no operator will touch alpha, full stop. That includes writes. the data is simply classed as 'not-present', even if it was previously created.

NOTE: many operators, will create a completely new image to replace an old image during its processing. If alpha is off that new image will NOT get a copy of the alpha channel, and the data will be lost. -fx and -composite will do this (I think). -evaluate and -level which modifies images directly will not. However none of these operators will see or modify alpha while it is off.
I don't understand why someone would want to do the latter --- turn it off, then on, all in the same command line.
One example was above...

In an API like Magick++ or PerlMagick where operators that create new replacement images, but does not delete the old images for you like the command line API does, being able to turn off alpha temporarily in a source image can be useful.

Most operators however give you the -channel operator controls. but other operators may not.

Basically it is providing low level access to some of the image control. We do not expect people to do this type of thing very often. The 'on' method should be VERY rarely used, if EVER!

More common should be 'set' (equivelent to -matte)to ensure an image just created or read in has an alpha (and it is opaque if the image did not have one).
Thus why is there a need for a difference between -alpha on/activate and -alpha set? (Not that extra options are bad)
Because 'on' is just a switch, the image itself may, or may not change, depending on its past history. 'set' enables alpha but makes sure the image looks exactly the same as it was before the -alpha set operation regardless of any past history or 'baggage'.

Basically 'on' can have unexpected results with an image that this 'code block' was given. Where 'set' will ensure the image remains 'as given'.


Bonus Points: The reason 'Copy' does like it does, and I insisted it was purely a copy, (unlike the 'Shape' variation) is that you may need the alpha channel to be the same as all the other channels.

This is vital for using a gradient image in operators like -clut. However having said that I have not yet analyzed and maybe fixed the -clut to correctly use a gradient with alpha LUT. I attempted to do tis previously but held off until -alpha copy was properly working.

Re: unclear about -alpha on with IM 6.4.3-8

Posted: 2008-09-23T17:43:40-07:00
by fmw42
Thanks. That helps.

Also I do understand and like the new -alpha copy capability.