Batch-converting images

June 29, 2010

I had a wad of images that I needed to resize from 300dpi and high-resolution jpg to 4.5×6 (or 6×4.5) low resolution at 72 dpi.

First, I installed ImageMagick:
sudo aptitude install imagemagick

Then I opened GIMP and determined the pixel width and height of one image. (Image -> Canvas Size). In my case, it was 3264×2448.

Next, I resized the image to the size I wanted. That turned out to be 432×324.

In other words, I wanted my new images to be 0.132352941 of the original image. A quick test told me I was on the right track:

convert P4250049.JPG -resize 13.2352941% test.jpg

The first time I did this I forgot the % sign and got a 13×10 pixel image – not exactly what I wanted.

So, on to batch-converting everything in a directory:

mkdir ./resized
for i in *.JPG; do
echo $i
convert $i -resize 13.235941% -quality 20 ./resized/$i

And all my resized images were in the resized directory below the image directory. (Did I mention I wanted to reduce the quality so my images would be smaller too? Yep, that’s what the -quality line does.)


Straightening pictures with Gimp

April 15, 2010

A while back, I discovered a very useful tool in Gimp to straighten images. This is useful if you have a bunch of scanned text (its advertised usage) or if you have what I have: a group of pictures that were scanned in on a flatbed scanner and all 2-3 degrees off of horizontal.

Since upgrading Ubuntu, I’d lost track of that plugin. I started by searching for “straighten picture” and that led me to the Straighten and Crop plugin:

That’s a useful tool, but not what I wanted. (It lets you pick two points on an image–say, the leftmost and rightmost horizon lines–and rotate the image so those two points are even.)

Eventually I figured out the tool I wanted was Deskew (aka auto-straighten). It can be found here:

I downloaded the .deb for 1.1 and installed it in my Ubuntu 9.10 with:

sudo dpkg -i gimp-deskew-plugin_1.1_i386.deb 

Once it’s installed, it’s not immediately obvious where in Gimp it goes. (And of course the web page is no help.) The secret location is:

Filters -> Misc -> Deskew

Load an image, select that, and the image will be straightened. Then you can crop it and save it; nobody will ever know it wasn’t straight on your scanner.