Help:Strange Things when disable Alpha

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Help:Strange Things when disable Alpha

Post by Axolotl »

Hi i'm Newbie.
I have such a problem. When i resize image with transparent alpha background with IM, and then trying to disable alpha channel "-Alpha off" or just write to bmp using BM3: some huge multicoloured halo appears over the image, not the semi-transparent pixels after antialiasing, but much more. This Happens not matters if i use before disabling alpha "-alpha -threshold" or not.
Here before "-alpha off"
Image
and here After
Image

what i do wrong?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help:Strange Things when disable Alpha

Post by fmw42 »

your alpha channel is not binary and is trimming some of the white areas or making them partially transparent against the black background.

You can see that by alternating views between the original, image with out alpha and image of alpha channel

to get the latter two

convert 81362956.png -alpha off 81362956_aoff.png
convert 81362956.png -alpha extract 81362956_alpha.png
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Re: Help:Strange Things when disable Alpha

Post by Axolotl »

Yeah, thanks for tip. The solution is to use "-alpha background" before "-alpha off"
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Help:Strange Things when disable Alpha

Post by anthony »

Alpha background only sets the color of pixels which are fully transparent. It does not effect the color of semi-transparent pixels, whcih is the color you see when you true off alpha.

The BEST way to handle this if to overlay the image onto a background of the right color.
and there are two method in IM that are commonly used for this purpose.

The first is to 'flatten' the image onto a background...

Code: Select all

    -background {color} -flatten -alpha off
This is the most common method the whole technique has become known as 'flattening' images, though really it is more a 'set image background' operation. however it only works for one image, as the operators real task is to 'flatten' multiple images into a single image.

The other common method will work for a sequence of images, and will leave the images separate, but with the transparency replaced by the boarder color.

Code: Select all

   -bordercolor {color} -border 0 -alpha off
Other operators can also do this too, but the operators 'normal' actions more often than not gets in the way. These operators include... -mosaic, -layers merge, -frame, -coalease.

However what you are really trying to do (in full) is..

Code: Select all

    ....  \( +clone -alpha opaque -fill {color} -colorize 100% \) \
          +swap -geometry +0+0 -compose Over -composite -alpha off ....
The above has now been collected together in IM examples, Basics,
Removing Alpha transparency
http://www.imagemagick.org/Usage/basics/#alpha_remove

This section now replaces all the other sections and bits around IM Examples that previously looked at or discussed removing alpha channel, Such as
JPEG Transparency - NOT
http://www.imagemagick.org/Usage/format/#jpg_trans
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
amar_nishant

Re: Help:Strange Things when disable Alpha

Post by amar_nishant »

Try
-alpha on or -alpha set
-background none
Post Reply