63

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.

8 Answers 8

105

Easy. Install imagemagick:

sudo apt install imagemagick

Its 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

Read also as:

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
4
  • Is this supposed to print Converting filename.tif or Converting filename? Oct 1, 2014 at 2:20
  • 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, 2014 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, 2017 at 16:31
  • I get this warning when I run that snippet: > convert-im6.q16: Wrong data type 3 for "GainControl"; tag ignored. `TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/985.
    – Raleigh L.
    Aug 11, 2022 at 8:13
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
5
  • 2
    Yay for built-in filename handling.
    – beerbajay
    May 6, 2014 at 15:43
  • This worked great for me with png files as well. The behavior for pdf's was different, however.
    – wdkrnls
    Mar 28, 2015 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, 2015 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, 2015 at 11:54
  • For a large number of files, this runs into memory issues. I split mine into few batches to use this.
    – abhaga
    Apr 27, 2020 at 15:23
5

Use mogrify, the tool intended for batch processing inside ImageMagick

mogrify -format jpg *.tif

In case you don't have ImageMagick:

sudo apt-get install imagemagick
0
2

I would like to add to @Matt's answer that if you would like the files to be saved in the subfolders you can do the following:

find . -iname *.tif | while read f; do echo "Converting ${f}"; convert "${f}" "${f%.*}.jpg"; done

This also handles the issue if your file-path/name has spaces in it.

1

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.

0
1

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.

1

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'))
2
  • for f in *.tif won't error out, but convert *.tif will.
    – muru
    Aug 18, 2017 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, 2017 at 1:34
1

The GIMP GUI Solution Using a Batch Process Plugin

Works in Ubuntu 18.04 using GIMP 2.8

Batch Processor Input dialog window

David's Batch Processor input dialog window

Batch Processor output dialog window

Batch Processor Output Dialog Window

Installation Instructions

  1. Download the current plugin file from DBP - David's Batch Processor homepage to your desktop. For Ubuntu 18.04 running Gimp 2. 8 the file that worked for me was dbpSrc-1-1-9.tgz.

  2. Grab some GIMP development files:

    sudo apt-get install libgimp2.0-dev gcc cpp g++
    
  3. Switch to the system source code directory:

    cd /usr/src/
    
  4. Extract the plugin from your Desktop to its own source code directory. Replace [username] with your current username, and use the filename that you downloaded above in step 1:

    sudo tar -xvzf /home/[username]/Desktop/dbpSrc-1-1-9.tgz
    
  5. Change to the plugin's source code directory:

    cd dbp-1.1.9
    
  6. Compile the plugin:

    make
    
  7. Install the plugin:

    sudo make install
    
  8. Start GIMP and you will find the plugin under Menu > Filters > Batch Process

    GIMP Batch Process.. Menu Path

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .