Friday, January 07, 2011

A Glimpse of the Past, and Command Line Adventures

Kodachrome slide from 1951 or 1952. My Aunt Verla, Uncle Bill, and cousins Cathy, Bobby, and Denny. Aren't they cute?

The last few days I've been scanning a box of old Kodachrome slides my mom shot with her spiffy Exacta 35mm camera in the early 1950's. It's the camera I fell in love with as a teenager, using black and white film. A few years ago, I sold the camera on Ebay to a collector in Germany, sort of a photographic repatriation.

I've never seen these images before--they were something Mom always told me she'd show me someday, but it never happened, and it was purely by chance that I found and kept the metal slide box when I emptied her house in 1996.

It's sort of spooky to see images from her life long before she was my mother. In fact I was so focused on this glimpse into her life that I didn't notice I was scanning the images in a format my photo editing software doesn't much like. I want to print some of these pictures to send my cousins (Do you suppose they know how cute they were?), so I need to convert them to a different file format in batch mode.

Fortunately, I have ImageMagick on my Linux box already, and it has awesome command line tools (about which I know very little, so far). I do know how to convert a file format:

rebecca@hecate:~/Moms_slides$ convert covered_bridge.tiff covered_bridge.jpg

Of course, I need to do batches of convert. I could read the ImageMagick documentation (but if that were easy, I would have done it years ago). Or, I could make an executable file of convert commands, and run it. There was a time when I wrote sed and awk scripts in my sleep (I really did--I dreamed about shell scripts.) I was afraid I couldn't remember, but a little help.txt file in an archived directory jogged my memory, and I was back in business directly.

In the spirit of my help.txt files, where I kept a record of how I did whatever needed doing, here's how I converted a big pile of tiff image files to png image files.

rebecca@hecate:~/Pictures/Moms_slides$ ls *.tiff|
awk '{print "convert "$1, $1".png"}'|
sed s/.tiff.png/.png/ >temp
rebecca@hecate:~/Pictures/Moms_slides$ chmod +x temp
rebecca@hecate:~/Pictures/Moms_slides$ ./temp

And here's what the executable file looks like:

rebecca@hecate:~/Pictures/Moms_slides$ head temp
convert 5kids_easter2.tiff 5kids_easter2.png
convert 5kids_easter.tiff 5kids_easter.png
convert 5kids_pinecones.tiff 5kids_pinecones.png
convert 5kids_xmas.tiff 5kids_xmas.png
convert bill1.tiff bill1.png
convert bill2.tiff bill2.png
convert bill_junglegym.tiff bill_junglegym.png
convert bobby_blocks.tiff bobby_blocks.png
convert bobby_easter.tiff bobby_easter.png
convert bobby_junglegym.tiff bobby_junglegym.png

It took a lot longer to write up this help file than it did to convert 75 images to a format I can send to my printer. (For what it's worth, my photo editing software can read tiff files, just not the ones created by Xsane, the scanner software I use.)

Here are some Web resources on sed and awk that I wish had existed when I was learning those wonderful programs:

4 comments:

Goose said...

Another handy way to do commands like that where you need to translate part of the filename is with a sh for loop, and bash's "parameter expansion"

for i in "*.tiff"; do convert $i ${i.%jpg}.png; done

Theres a section in the bash manpage "SHELL PARAMETER EXPANSION" that show how to use the curly braces to fiddle with the value of a variable.

Reya Mellicker said...

They really ARE cute. I love our old family slides.

I loved White Noise when I read it but I bet I wouldn't now. Novels ... I used to read them but I just don't like them anymore. There is so much non-fiction I'm interested in - is that it?

Happy Tuesday, Rebecca.

Rebecca Clayton said...

Goose,
That's so cool! I'll try that right away!

Rebecca Clayton said...

Reya,
I enjoy nonfiction more than novels these days too. What's up with that?