Command line tool for image conversion

35,013

Solution 1

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.

Solution 2

Try Convert. It can do a lot.

Share:
35,013

Related videos on Youtube

Void Star
Author by

Void Star

Hi, my name is Kyle. I have been interested in science, math, and engineering for (quite literally) as long as I can remember. I am an avid programmer and electronics hobbyist. I attended the University of Washington as an undergraduate in the Electrical Engineering department and now work for Keysight Technologies as a research and development software engineer.

Updated on September 18, 2022

Comments

  • Void Star
    Void Star over 1 year

    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
    Void Star over 11 years
    Yeah, that's what I'm looking for. 8 minutes before I can accept answer.
  • Void Star
    Void Star over 11 years
    zmode gave more specific details, so I'm accepting his answer. Thanks!
  • UtahJarhead
    UtahJarhead over 11 years
    What shell is your syntax for?
  • UtahJarhead
    UtahJarhead over 11 years
    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
  • sean christe
    sean christe over 11 years
    The posted code is MS batch.
  • user2284570
    user2284570 over 9 years
    @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
    user2284570 over 9 years
    @galuano1 : Your link is dead.
  • galuano1
    galuano1 over 9 years
    @user2284570 Updated the link.
  • Marnes
    Marnes over 4 years
    Just to amend, the docs clarify that it will pick the format from binary signatures first (as it should), and then the extension.
  • user3405291
    user3405291 over 3 years
    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"