11

Possible Duplicate:
Free command line image converter

I need a command line tool for windows which can be used to convert an image from any common format to 24 bit bitmap. I'm writing some programs to do image manipulation in C, but I don't really want to write a ton of code to read images in multitudes of formats. I use bitmap format a lot for both reading and writing because it's pretty straight forward. I don't really want to convert all of the images by opening in paint and saving in the desired format.

Void Star
  • 515
  • 2
  • 9
  • 23

2 Answers2

21

ImageMagick can do format conversions with a tool that comes with it called convert. You can find binaries for it here.

You'll want to run something like this on Windows:

for %%f in (*.jpg) do (
       convert "%%~nf.jpg" -type truecolor "%%~nf.bmp"
)

Or in Bash:

for f in *.jpg; do convert "$f" -type truecolor "${f%.*}.bmp"; done

Convert picks the format automatically from the extension and -type truecolor makes sure you are converting to 24-bit.

pdem
  • 103
  • 4
dset0x
  • 2,215
  • 15
  • 13
  • What shell is your syntax for? – UtahJarhead Oct 15 '12 at 19:06
  • It doesn't look like bash, so here's the above in bash: `for f in *.jpg; do convert "$f" -type truecolor "${f%.*}.bmp"; done` – UtahJarhead Oct 15 '12 at 19:08
  • 2
    The posted code is MS batch. – EBGreen Oct 15 '12 at 19:15
  • It should work as a windows batch script, since that's what Big Endian is running. It is however, untested, as I do not have a windows installation. – dset0x Oct 15 '12 at 19:16
  • @zmode : How I can do if I have color images and black and white images in the same directory *(scanned documents)*? Since this is for sending in a mail' I fear getting larger images for black and white ones *(1 bit for color)* by adding colorfull informations *(eg : switching from 1 bit to three bytes RGB per pixel)*. So, is it possible to to convert the format without converting color images to black and white or vice versa? – user2284570 Feb 05 '15 at 18:16
  • Just to amend, the [docs](https://www.imagemagick.org/script/command-line-processing.php#output) clarify that it will pick the format from binary signatures first (as it should), and _then_ the extension. – Marnes Dec 26 '19 at 17:57
  • While installing ImageMagick, I marked the checkbox `Install legacy tools like convert`. Also, I had to use the complete path for convert to make it work: `"C:\Program Files\ImageMagick-7.0.10-Q16-HDRI\convert.exe"` – Megidd Oct 26 '20 at 05:24
5

Try Convert. It can do a lot.

galuano1
  • 189
  • 5