Processing Scanned Images on the Command Line

So I’ve done a bunch of scans on my scanner, into TIF images, 600dpi, perfect for for archiving. But I need to rotate them correctly, and shrink them into more usable JPEG files. Here’s how:

For the rotation, I used an EXIF tool appropriately named ‘ExifTool’ to change the orientation setting on the file, without modifying any of the image data. If you’re feeling commandline lazy, you can also setup an apple script (open it in the Apple Script editor, save as an Application, then drag your images onto it, it works in a batch so drag all the similarly-orientated images together).

Now the TIF’s are all good, I wanted to convert into JPEGs. The best way is with ImageMagick.

mogrify -auto-orient -resize 800x800 -format jpg -quality 80% *.TIF

Mogrify is a batch processing tool that by default will overwrite the input file, so it’s a little dangerous. But by inputting a .tif, and outputting a .jpg it will *not* overwrite the tif’s since the filename is different. But if you’re scared, just copy the tif files to a new directory.

I modified the linked script to include an “Upside Down” option, my updates are here:

on open filenames
	set question to display dialog "Exiftool rotating tool frontend
Which side to rotate?" buttons {"Left", "Right", "Upside Down"} default button 1
	set answer to button returned of question
	if answer is equal to "Cancel" then
		tell me to quit
	end if
	if answer is equal to "Left" then
		set orientation to "8"
	else if answer is equal to "Right" then
		set orientation to "6"
		set orientation to "3"
	end if
	repeat with fn in filenames
		set filename to POSIX path of fn
		do shell script "exiftool -n -Orientation=" & orientation & " '" & filename & "'  >>~/Library/Logs/exiftool.log 2>>~/Library/Logs/exiftool.eror.log"
	end repeat
end open

Leave a Reply

Your email address will not be published. Required fields are marked *