For some time, I’ve been taking part in Stu’s Tuesday Challenge.
Recently, Stu has had great success with his East Midlands wedding photography business and so doesn’t have time for the Challenge any more.
So I’ve taken over the Challenge and rebranded it the Photo Challenge (so I’m not tied to a Tuesday). I hope the regular contributors on Stu’s blog will continue to take photos for the Challenges. It’s also an ideal opportunity for new photographers to try their hand at some of the challenges and get some feedback.
Why not give it a go?
I recently had a need to convert 3,000 scanned TIFF images to a more sensible format for distribution, such as JPEG. I’ve been using GIMP to edit the individual photos but sadly it doesn’t have a batch format conversion tool.
So I wrote my own little script in bash. You will need to install ImageMagick (a commandline image editor) on your box first, but this is bundled with most distributions and be installed from a repository.
Things to be aware of when using this script:
- It does not recurse into subdirectories – you have to place the script in the same directory that the TIFFs are in
- At the time of writing, ImageMagick is single-threaded and can only use one core of a multicore CPU. If you want to use N cores, you have to split the photos into N directories and run N copies of the script. However be aware that, in my case at least, each TIFF was around 45MB and took between 1 and 1.5 seconds to convert. This means the disk is reading at maybe 40MB/s, so running two threads you will quickly hit the limit of your disk.
- You can change the compression of the JPG by altering the value
85 in the script below.
- You can also convert your TIFFs to other formats. See
man convert for details.
Finally, the code you’ve all been waiting for. Feel free to use, edit, distribute this anywhere you please.
#!/bin/bash
total=`ls *.tif | wc -l`
count=0
ls *.tif | while read i
do
file=`basename "$i" .tif`
echo $file
convert "$file.tif" -quality 85 "$file.jpg"
count=`expr $count + 1`
percent=$(($count / $total))
echo $percent% completed, done $count of $total
done
echo All done!
Categories: Guides, Linux, Photography Tags: bash, convert, GIMP, ImageMagick, JPEG, JPG, photo, script, TIF
For those of you who don’t know, I’m taking part in a weekly photo challenge, namely Stu’s Tuesday Challenge.
This week the challenge is not to take a new photograph, but to submit the best photo we’ve ever taken. I’ve managed to whittle it down to 2 photos, but I can’t decide between them.
So I’ve set up a poll.
Please register your vote over at my photo blog. The poll is in the top corner of the site, and will be open until Monday 22nd June! The winning photo will be submitted on that day. Thanks!