Converting monochrome frames to transparent animated GIF

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
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

I updated ImageMagick, and this command stopped working:

Code: Select all

convert -delay 5 input-*.pnm -transparent white -dispose Background -coalesce -layers optimize output.gif
Before the update, it would take a bunch of monochrome images, and output an animated GIF with the white color replaced by transparency.
After the update, the output now has all the frames overlaid on top of each other.
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Re: Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

In fact, I can't even find a way to simply replace white with transparency in an animated GIF. -transparent-color never seems to do anything.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting monochrome frames to transparent animated GIF

Post by fmw42 »

I am not an expert on animations, but try moving -coalesce to right after your input image read

convert -delay 5 input-*.pnm -coalesce -transparent white -dispose Background -layers optimize output.gif
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Re: Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

Nope, that doesn't change anything. I've tried quite a lot of combinations with those options. I don't think it's possible using any options mentioned in this thread.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting monochrome frames to transparent animated GIF

Post by fmw42 »

try adding -loop 0 to your command. Perhaps it needs to be explicitly set. -loop 0 should make it animate and loop repeatedly.

Hopefully Anthony will be able to look at this post and give you more help as he is the animation expert.

It is possible that monochome images (-depth 1) does not support transparency. You could try adding -depth X -type grayscale with X=1,2,4,or 8 and see what happens. Also possible adding -colors Y where Y is the equivalent number of colors for the depth. EG depth=8 is 256 colors.

This seems to work fine for me on IM 6.6.7.1 Q16 Mac OSX Tiger unless I am missing something here:

convert logo: -resize 50% logo2.gif
convert -delay 20 logo2.gif logo2.gif logo2.gif -coalesce -monochrome -transparent white -loop 0 logo2_anim3.gif
identify -verbose logo2_anim3.gif



Image: logo2_anim3.gif
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 320x240+0+0
Resolution: 72x72
Print size: 4.44444x3.33333
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit

Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: -0 (-0)
kurtosis: 0
skewness: 0
Alpha:
min: 0 (0)
max: 255 (1)
mean: 34.7902 (0.136432)
standard deviation: 87.528 (0.343247)
kurtosis: 2.48763
skewness: -2.1184
Alpha: none #00000000
Histogram:
66322: ( 0, 0, 0, 0) #00000000 none
10478: ( 0, 0, 0,255) #000000 black
Colormap: 2
0: ( 0, 0, 0,255) #000000 black
1: ( 0, 0, 0, 0) #00000000 none

Rendering intent: Undefined
Interlace: None
Background color: black
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 320x240+0+0
Dispose: None
Delay: 20x100
Scene: 0 of 3
Compression: LZW
Orientation: Undefined
Properties:
date:create: 2011-01-19T11:03:09-08:00
date:modify: 2011-01-19T11:03:09-08:00
signature: 9beeece335618c22906f85e124a6625963de1389edde28ae0c3d6018080bf59f
Artifacts:
verbose: true
Tainted: False
Filesize: 7.49KBB
Number pixels: 76.8KB
Pixels per second: 1.536MB
User time: 0.030u
Elapsed time: 0:01.049
Version: ImageMagick 6.6.7-1 2011-01-15 Q16 http://www.imagemagick.org
... for two other frames
Last edited by fmw42 on 2011-01-19T12:12:01-07:00, edited 1 time in total.
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Re: Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

The problem isn't with the looping or anything - it's just that each frame of the resulting GIF is the result of overlaying all the frames before it.

Whether the input is monochrome or not doesn't matter. As I mentioned, I can't even replace white with transparency in an animated GIF. For example, can you make this GIF have a transparent background?

For the record, my IM version is: ImageMagick 6.6.5-6 2010-11-19 Q8
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting monochrome frames to transparent animated GIF

Post by fmw42 »

Your problem is that you already have transparency. So you need to enable transparency and tell -transparent the rgba color. So this works for me:

convert example.gif -channel rgba -alpha on -coalesce -transparent "rgba(255,255,255,255)" -loop 0 example2.gif

Image: example2.gif
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 100x100+0+0
Resolution: 72x72
Print size: 1.38889x1.38889
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: -0 (-0)
kurtosis: 0
skewness: 0
Alpha:
min: 0 (0)
max: 255 (1)
mean: 93.636 (0.3672)
standard deviation: 122.921 (0.482042)
kurtosis: -1.69641
skewness: -0.55099
Alpha: none #00000000
Histogram:
6328: ( 0, 0, 0, 0) #00000000 none
3672: ( 0, 0, 0,255) #000000 black
Colormap: 2
0: ( 0, 0, 0,255) #000000 black
1: ( 0, 0, 0, 0) #00000000 none

Rendering intent: Undefined
Interlace: None
Background color: black
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 100x100+0+0
Dispose: None
Delay: 5x100
Scene: 35 of 36
Compression: LZW
Orientation: Undefined
Properties:
date:create: 2011-01-19T11:17:07-08:00
date:modify: 2011-01-19T11:17:07-08:00
signature: c68752ddad146a6607eb65fe1bf31d86ade5263faaae48007ea7d5d467364467
Artifacts:
verbose: true
Tainted: False
Filesize: 12.1KBB
Number pixels: 10KB
Pixels per second: 3.17KB
User time: 1.740u
Elapsed time: 0:04.149
Version: ImageMagick 6.6.7-1 2011-01-15 Q16 http://www.imagemagick.org
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Re: Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

Erm... that GIF has no transparency. It has a white background: http://thecybershadow.net/misc/3davatar ... ample.html

That command results in the same broken output for me: http://thecybershadow.net/misc/3davatar ... ample2.gif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting monochrome frames to transparent animated GIF

Post by fmw42 »

try upgrading your version of IM to the latest version 6.6.7.1 Q16 It works fine for me as I showed above.


Histogram:
6328: ( 0, 0, 0, 0) #00000000 none <---- transparent (black)
3672: ( 0, 0, 0,255) #000000 black <---- opaque black
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Re: Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

My operating system doesn't provide a package for any versions newer than mine :/ And I don't want to risk a global tarball install as other components depend on IM. I guess I'll just downgrade for the time being.
CyberShadow
Posts: 14
Joined: 2010-05-02T18:05:02-07:00
Authentication code: 8675308

Re: Converting monochrome frames to transparent animated GIF

Post by CyberShadow »

Downgrading fixed it. Problem solved, I guess. Thanks for the support.
Post Reply