(Batch) convert a BMP to a PNG with transparency

3

I have +- 500 .bmp's that I would like to convert to .png's. It would be especially nice if the color white (#FFFFFF) of the original BMP's could be converted to transparent in the .png's.

PNG-8 is enough since the .bmp's are 16-colors.

I would prefer a command-line tool that I can put in a batch file, but any would be useful. Do you know of such a tool?

edit: The OS I use most is Windows 7 x64, but I also have Cygwin and various linuxes available

dtech

Posted 2011-09-26T19:01:37.803

Reputation: 669

Answers

6

ImageMagick can do this - have a look at the Convert command, which allows you to specify a colour to be used as the transparency value:

http://www.imagemagick.org/script/convert.php

Linker3000

Posted 2011-09-26T19:01:37.803

Reputation: 25 670

if you want to run it as a bash script for batch conversion in a whole folder full of files: for file in *.png ; do convert "${file}" -transparent '#ffcc66' "batch/${file}" ; done – Sameer Shemna – 2014-10-21T10:09:55.630

2That definitly seems promising. conver -transparent white source.bmp dest.png does exactly what I want, however only mogrify supports multiple files and it only has -transparent-color which doesn't really work. Looking further – dtech – 2011-09-26T19:35:36.123

Ultimately I just used a script with a loop. For those, interested, effictive code was convert -transparent white $f ${f%bmp}png – dtech – 2011-09-26T20:26:14.257

@dtech: and your system was Windows, Linux, Mac, android.... ? – woliveirajr – 2011-09-26T20:27:44.437

@woliveirajr it was a bash shell, other shells should allow simalar constructs – dtech – 2011-09-29T12:24:57.517

3

Using what operating system, etc ?

One suggestion - generic answer: give a try to ImageMagik.

Right from the first page you can get:

Format conversion: convert an image from one format to another (e.g. PNG to JPEG). Transparency: render portions of an image invisible.

Usage example:

convert file.jpg -transparent-color '#ffffff' file.png

woliveirajr

Posted 2011-09-26T19:01:37.803

Reputation: 3 820