Hi, I'm trying to programatically create and apply an alpha mask to an image. I can achieve this in GIMP but I have no idea how to achieve this in imagemagick. Can anyone help out.
Basically I'm doing this to work around a bug with Flash CS4 which fails to anti-alias png exports if you've certain specific features.
The process is as follow
From Flash I export a 24bit (no alpha) png with a white background - White.png
From Flash I export a 24bit (no alpha) png with a black background - Black.png
From Flash I export a 24bit (With alpha) png with a transparent background (Looks crap) - Broken.png
In GIMP I open White.png, add Black.png as a new layer with blending set to 'Difference Mode'
I flatten the image and save it as an alpha mask. - mask.png
I then open Broken.png - remove the alpha, and add mask.png as a new alpha mask.
The results are then perfect.
Could someone point me in the right direction to get started making this work with ImageMagick.
Creating and applying an alpha mask.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Creating and applying an alpha mask.
It would really help to see your images, especially as we don't know what GIMP difference does nor what your objective really is for this image. In the mean time, look at
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/channels/
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/channels/
Re: Creating and applying an alpha mask.
Here's the images for you to look at, to better explain what I'm trying to achieve.
Here's the original broken output from Flash. This only happens if you output to png with alpha and use paths or bitmap fonts.
Here's my White background png with no alpha. Aliasing works fine here
Here's my Black background png with no alpha. Aliasing works fine here
Here's the mask I create by combining the black and white with a difference blending mode
And here's the end result which I achieve by taking the original broken output and replacing the alpha channel with my newly creating mask.
Now I just need to figure out how to achieve the same result using ImageMagick so that I can automate the process.
Obviously life would be easier if Adobe would just fix the bug
Here's the original broken output from Flash. This only happens if you output to png with alpha and use paths or bitmap fonts.
Here's my White background png with no alpha. Aliasing works fine here
Here's my Black background png with no alpha. Aliasing works fine here
Here's the mask I create by combining the black and white with a difference blending mode
And here's the end result which I achieve by taking the original broken output and replacing the alpha channel with my newly creating mask.
Now I just need to figure out how to achieve the same result using ImageMagick so that I can automate the process.
Obviously life would be easier if Adobe would just fix the bug
Re: Creating and applying an alpha mask.
I've done it. It wasn't as difficult as I imagined either.
composite -compose difference Black.png White.png Mask.Png
convert Mask.png -negate Mask_Inverted.png
composite -compose CopyOpacity Mask_Inverted.png Broken.png Fixed.png
Cheers all.
composite -compose difference Black.png White.png Mask.Png
convert Mask.png -negate Mask_Inverted.png
composite -compose CopyOpacity Mask_Inverted.png Broken.png Fixed.png
Cheers all.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Creating and applying an alpha mask.
Your mask make make the whole image semi-transparent. You may need to process your mask a little further. Such as using threshold. or prehaps the very complex and advanced
method given in
http://www.imagemagick.org/Usage/channe ... antialised
The examples before that link also look at using difference image masking.
method given in
http://www.imagemagick.org/Usage/channe ... antialised
The examples before that link also look at using difference image masking.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/