Problem with alpha channel

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
Baldrian

Problem with alpha channel

Post by Baldrian »

I have a Problem with the conversion of a png with full alpha channel to a gif.
If I convert it without any parameters the image has no antialiasing so i tried to set a white background to the png before converting, but i failed.

Some of my tries:
convert -background white request.png 1.gif (no effect)
convert +matte request.png 3.png (grey background)
convert +matte -fill white request.png 3.png (same)
convert +matte -background white request.png 3.png (same)
convert +matte -background white -mattecolor white request.png 3.png (same)
convert -channel matte -threshold -1 +matte request.png 3.png (same)
.....

can somebody help me?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with alpha channel

Post by fmw42 »

convert request.png -channel RGBA -matte 4.gif

This should work, i.e. have an alpha channel but it will be off, but it should be there.

However, I think you have a bug.

I tried first with png:

convert rose: -channel RGBA -matte rose.png
convert rose.png -verbose info:
Image: rose.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 70x46+0+0
Resolution: 72x72
Print size: 0.972222x0.638889
Units: Undefined
Type: TrueColorMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit

So there is an alpha.

But doing the same with gif:

convert rose: -channel RGBA -matte rose.gif
freds-mac-mini:~ fred$ convert rose.gif -verbose info:
Image: rose.gif
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 70x46+0+0
Resolution: 72x72
Print size: 0.972222x0.638889
Units: Undefined
Type: Palette
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit


This shows no alpha channel enabled.

I am using IM 6.4.1-8 Q16 (HDRI)

Unless I don't understand alpha with gif, you should report this to the Bugs forum.
Baldrian

Re: Problem with alpha channel

Post by Baldrian »

> convert request.png -channel RGBA -matte 4.gif

I tried this, but the result is a gif with transparency. And the effect to have no antialiasing on the outline of the image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with alpha channel

Post by fmw42 »

Sorry I missed the part about anti-aliasing. GIF does not support full 8-bit anti-aliasing.

It will take a gradient alpha and make it 50% on and 50% off.

see http://www.imagemagick.org/Usage/formats/#boolean_trans


I am not sure this will work, but you might try flattening the alpha into the png to "burn-in" the antialiasing into the underlying image and then just converting to gif. I have not tried this, so I cannot say if that makes any sense or will work.

convert image.png -flatten image.gif
Baldrian

Re: Problem with alpha channel

Post by Baldrian »

ITS WORKING!

Thats exactly what I wanted. Thanks a lot.
Post Reply