I'm trying to mass convert a handful of .tif files. I found phatch could look like a good candidiate but I'm running Ubuntu 11.04. Looks like they don't have a .deb for my version.

Anyone have any alternatives to phatch or any other recommendations as to quickly batch convert tif to jpeg files.

I'm looking for a non-Photoshop (ala Wine) solution.

up vote 62 down vote accepted

Easy. Install imagemagick:

sudo apt-get install imagemagick

It's simplest usage is:

convert File.tif File.jpg

It is smart and goes by your file extension.

Now, for doing batch conversions, we shall use a loop.

cd into the directory where your tif files are.

then:

for f in *.tif; do  echo "Converting $f"; convert "$f"  "$(basename "$f" .tif).jpg"; done

That should do it!

Also, once you convert all of the files and verify the new jpg's integrity, just run rm *.tif in that directory to delete all your old .tif files. Be careful with asterisks though, don't add a space after the *, or you will delete all your files in the directory.

Tip: If you have a folder with subfolders that holds these images. You could use this for loop to find all .TIF files within that folder:

for f in $(find -name *.tif); do ...; done
  • Is this supposed to print Converting filename.tif or Converting filename? – sodiumnitrate Oct 1 '14 at 2:20
  • 1
    works great Matt. Thank you! – Coldstar Oct 28 '14 at 19:19
  • 1
    @sodiumnitrate it will say "Converting filename.tif". the basename command takes 2 arguments, for example basename file.tif .tif will return "file" stripping the .tif extension away. You could modify the loop to say "Converting filename.tif to filename.jpg" with the same basename command, if you wished. – Matt Dec 7 '14 at 0:44
  • find's first arg shoud be the path, so that last line should be for f in $(find . -name *.tif); do ...; done (since we cded in the directory before). I tried editing @Matt's answer but edits must be at least 6 chars for some reason. – mrtnmgs Aug 22 '17 at 16:31

I found this question while trying to do it myself, for future reference you can also do it like this:

convert *.tiff -set filename: "%t" %[filename:].jpg

or to put it in a subdirectory

mkdir jpg
convert *.tiff -set filename: "%t" jpg/%[filename:].jpg
  • Yay for built-in filename handling. – beerbajay May 6 '14 at 15:43
  • This worked great for me with png files as well. The behavior for pdf's was different, however. – wdkrnls Mar 28 '15 at 5:04
  • I would love to see this working, however, this reported a Bus Error on ImageMagick 6.6.9-7 2014-03-06 Q16 (OpenMP) on Ubuntu 64. The accepted answer works fine. – TFuto May 1 '15 at 6:47
  • A word of warning: This froze for me the entire system (GNOME 3) and I had to hard shut down the computer – 0__ Jun 6 '15 at 11:54

Imagemagick should be able to convert them. It is a package of commandline programs, if you are OK with that.

Part of that is convert -

man convert:

convert - convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

  • 1
    Matt's answer is actually way more useful – marto Sep 7 '11 at 15:19
  • 1
    Yup. You're right there. – chrisjlee Sep 7 '11 at 15:26

If you prefer a GUI application, you can install Phatch through the normal repositories. Just open Ubuntu Software Center and search for it. I'm not on 11.04 anymore but I had it installed back then.

The answers above use *.tif for tif selection, but this will return an error if you have too many files in your current working directory. A simple workaround is to use a python script to convert each file in the cwd:

import glob, os

for c, i in enumerate(glob.glob('ecco_images/*')):
  print(' * converting', i)
  os.system('convert ' + i + ' ' + i.replace('.TIF','.jpg'))
  • for f in *.tif won't error out, but convert *.tif will. – muru Aug 18 '17 at 1:11
  • Ah, thanks @muru! I thought the * expansion would be the same at the os level, but am happy to be corrected. – duhaime Aug 18 '17 at 1:34

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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