Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent ImageMagick from using indexed colors?

I have some PNG images with transparency. However, whenever I do any operations with ImageMagick on the image (e.g. cropping), it changes some of the images to be "indexed" color instead of RGB. The images that change are ones where there happens to be fewer than 256 colors, but the conversion ruins the transparency.

From some research I found you can prepend a filename with png32: to force RGB, but that only works when using the convert command, not mogrify.

I can add -format png32 with mogrify, but that renames all the images to *.png32.

Supposedly you can do this:

mogrify -define png:format=png32 -format png *.png

But it doesn't work, the images are still indexed color not RGB. How do I force PNG32 with mogrify?

like image 907
DisgruntledGoat Avatar asked Jul 25 '15 20:07

DisgruntledGoat


1 Answers

Your command should have worked, if you are using a recent version of ImageMagick (6.9.1-3 or later).

Earlier versions will work if you use the -format png32 option as you did, then run a script to rename them back to *.png.

According to the ImageMagick 6 change log, the "-define png:format=png32" option was added to ImageMagick at version 6.7.3-0, but a bug was introduced at version 6.8.9-0 that caused it to be ignored in certain circumstances; that bug was fixed in version 6.9.1-3.

So the answer to your question is to either work around the problem by letting mogrify rename your input files to *.png32, or to upgrade your ImageMagick to 6.9.1-3 or later.

like image 102
Glenn Randers-Pehrson Avatar answered Nov 10 '22 15:11

Glenn Randers-Pehrson