I have a lot of bmp images like these:

enter image description here

That I need to convert to transparent png files like:

enter image description here

basically the blue color (#00FFFF) needs to turn transparent and the purple color (FF00FF) needs to turn into a grey color (#747474).

The BMP files are really old with a color depth of 8-bit, they are originally from the game "Heroes 3", I'm trying to port this game to webgl but the sprites are currently my biggest issue.

I have found this original topic in which imagemagick was recommended, however I can't figure out how to batch convert files in windows using imagemagick, nor how I would turn the purple color on the bmp to the actual grey value in the transparent png.

I'd really like some advice on this or an example of what the windows command prompt line would need to be in order to batch convert files with imagemagick.


Imagemagick's mogrifycan do this.

Your original (I converted it to BMP as it was PNG in SuperUser)

enter image description here

mogrify -format png -transparent #00ffff *bmp

enter image description here

You can also convert colours at the same time

mogrify -format png -fill grey -opaque #FF00FF -transparent #00ffff *bmp

enter image description here

Your image's shadow has an anti-aliased edge using colours like #FF96FF which probably needs to be merged into the transparent background or into the shadow. You can use the -fuzz option

mogrify -format png -fuzz 80% -fill grey -opaque #FF00FF ^ 
        -transparent #00ffff *bmp

enter image description here

Note that on Microsoft Windows, mogrify is not a separate command. You have to use the magick command as a prefix like this: magick mogrify ...

| improve this answer | |
  • Brilliant answer. SO to a tee. – david.pfx Apr 9 '17 at 10:36
  • You might want to mention that the command (at least on Windows and v7) is magick mogrify. It fixed my problem. – david.pfx Apr 9 '17 at 11:04
  • @david.pfx Thanks for pointing that out. Answer updated. – RedGrittyBrick Apr 9 '17 at 13:57
  • I had to throw single quotes around the -transparent hex code argument for it to run. ImageMagick 7.0.7-28 Q16 x86_64 2018-03-25 on Mac. – James Skemp Nov 1 '18 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.