Batch conversion and palette stuff

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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Post by glennrp »

Make a large image of all of your input images and then quantize that down to 256 colors.
  • convert -append *.bmp -colors 256 map.png

    for image in *.bmp do
    base=`echo $image | sed "s/.bmp//"`
    convert $image -map map.png -colors 256 -transparent "#ff00ff" $base.png
    done
If you aren't sure 255,00,255 is in your original images, then quantize
to 255 instead of 256.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Post by glennrp »

pinkfloydhomer wrote: This doesn't seem to work. First of all, I think you forgot a ";" after *.bmp. Also, the resulting .pngs are 32-bit color depth, not 8-bit. IrfanView reports that there is a palette anyway (I don't understand), but 255,0,255 is _not_ on index 0 in the palette.

Can you (or anybody) come up with another way to solve my problem?

/David

Whoops, you're right about the ";".
You could try PNG8:$base.png instead of just $base.png as the output name.
What version of ImageMagick are you using?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

You can make the 'map.png' file smaller by using the new -unique-colors operator. This shrinks the image down to one unique color per pixel.

Note 'magenta' (255,0,255) will probably NOT be present, after color quantization. See Quantization does NOT Preserve Colors
http://www.cit.gu.edu.au/~anthony/graph ... _not_exact

You can ensure it is added to the map by appending that color to it (after using one less
-colors argument to make room for it).
convert map.png xc:magenta +append map.png

If magenta is ment to be the transparent color you can set it as that using -transparent-color. If the images contain transparency get IM to ignore it using a -quantize transparent, before the -colors operator.
See Color Quantization and Dithering in IM Examples (see sig) for full details.

WARNING: there no current way of specifying the color index a specific color is to use in the final image, in IM.. Sorry.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply