Forcing 256 color 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
giorgiga

Forcing 256 color gif

Post by giorgiga »

Hi, I have a problem with ImageMagick doing too mutch of a good work reducing colors :)

I have a bunch of images I'm appending in a sprite, and I want the final output to be a 256-color gif – imagemagick keeps reducing colors to 128...
what option am I missing?

Code: Select all

convert -background white \
        \( \( clear.gif -resize 10x185! \) \( bg-header.gif -resize 10x169! \) -layers flatten \) \
        \( bg-menu1.png -resize 10x46! \) \
        \( bg-menu1-hover.png -resize 10x46! \) \
        \( \( \( bg-header.gif -resize 10x169! \) \( bg-menu1-start.png bg-menu1-end.png +append \)  -layers flatten \) -crop 10x46+0+0! \) \
        \( bg-menu2.png -resize 10x26! \) \
        \( \( \( bg-header.gif -resize 10x169! \) \( clear.gif -resize 10x46! \( bg-menu2-start.png bg-menu2-end.png +append \) -append \) -layers flatten \) -crop 10x26+0+46! \) \
        \( bg-tab.png -resize 10x30! \) \
        \( bg-tab-start.png bg-tab-end.png +append \) \
        \( bg-copyright.gif  -resize 10x32! \) \
        -append -colors 256 ../sito/img/bgs.gif
What I get is

Code: Select all

$ identify sito/img/bgs.gif
sito/img/bgs.gif GIF 10x467 10x467+0+0 8-bit PseudoClass 128c 2.5KB 0.000u 0:00.000
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Forcing 256 color gif

Post by fmw42 »

Not sure, but is it possible your images do not have 256 colors total. IM -colors make 256 colors or less if there are not enough colors. Also try adding -type truecolor and see if that changes things. Also do identify -verbose yourimage.gif and see how many colors are in the histogram or colormap.

What version of IM? If old, perhaps upgrading might help if there was a bug in your version.
giorgiga

Re: Forcing 256 color gif

Post by giorgiga »

ImageMagick version is the latest from macports :(

ImageMagick 6.5.9-0 2010-02-08 Q16

Unfortunately -type truecolor doesn't help (not does converting all input images to png – I just tried that).

I end up with visible dither in the output image (one the inputs is a gradient to use as a background), so definitely having 256 colors instead of 128 would help...

The really strange thing is that I also use a separate convert command to build a different css sprite, and in that case I end up with a 256-color gif (without having to specify either -colors 256 or -type truecolor)

I think I'll just switch to outputting .png and hack something to make it look good in IE6...

Thanks for your help fmw42

Do you think I should file a ticket in IM bugzilla (or whatever they have)?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Forcing 256 color gif

Post by fmw42 »

to avoid dithering add +dither to your command line.

if you post a link to your images, perhaps someone can figure out what is going on. It would be needed if you file a bug report on the Bugs forum, so the IM folks can see what is going on. It could just be your images have too few colors.
Post Reply