A 'Lockdown' Linux Project - Scan my old photos
The coronavirus lockdown has made everyone pause. Even though I have worked throughout and had to juggle home schooling for my boys, it has also given me a chance to slow down and reflect. I am always focused on the next project and very guilty of never fully taking stock of where I am. In an attempt to combat this unhealthy habit, I really wanted to dig through my old photos, remember the good times and re-share some of them. There are so many good memories going all the way back to my teenage years. It is a shame to be boxed into only sharing memories that have a recent digital heritage, when there are so many analogue memories in photos and slides.
So here is the technical story of how I was able to setup my scanning rig on Linux. As well as scanning, I was keen to back-date the EXIF data to reflect when the photos were actually taken. This would mean that any time the photos were indexed by a phone or by my website software it would accurately reflect the date the photo was originally taken.
Which scanner?
This is the first scanner I have ever bought, so I was unsure exactly how much to spend. On Amazon it is possible to buy scanners costing over a thousand pounds, which made me slightly concerned about what I would get for under a hundred. My first choice was the Epson V39 Reflection, pictured on right. It seems to have basic functionality, could scan at 300 dpi at a speed of 10 seconds per page.
After excitedly opening the box when it arrived, I really struggled to get my Linux machine to talk to it. I run Gentoo and followed the excellent Gentoo SANE page to get the sane-backend correctly configured. No matter what I tried, the scanimage -L command never seemed to work.
Eventually I was searching through the original SANE pages and noticed this. The Epson scanner I had purchased was completely unsupported. So this was duly returned and I then ordered a Canon LIDE 400 which was 'fully supported' according the the documentation. It was a very similar price, scanned at the same resolution and slightly faster a 8s per page.
Setting up the Canon LIDE 400 on Gentoo Linux
I'll cut to the chase here and let you know that at time of writing, the sane-backend on Gentoo is slightly out of date. The package is in search of a maintainer and currently version 1.0.27, which was released in 2017. With the Canon LIDE 400 supported for sure on 1.0.30, it meant I could not use the emerge packaged sane-backends. I had to download and compile the latest version instead, which is very usual for Gentoo.
When configuring the sane-backend, it is possible to specify the driver required for your device. The Canon requires the pixma driver, but I just compiled in all drivers as a precaution. Once installed and having set LD_LIBRARY_PATH to find the sane ld files, the following command finally worked:
don@falcon ~ $ scanimage -L
device `pixma:04A91912_43C057' is a CANON CanoScan LiDE 400 multi-function peripheral
To run scanimage as non-root, it is necessary to be part of the usb and scanner groups.
Scanning an image
I know that xscan is available but my instinct is always to use the command line because I expect to be scanning quite a lot of images, and I'll write a script to scan, clip, resize and tag. For now though, the following command works:
scanimage --device-name pixma:04A91912_43C057 --resolution 300 --format jpeg > photo.jpg
This fires up the scanner which makes the heartening juddering sound and then slowly scans the photo.
Setting the EXIF data
The best tool for working with EXIF tags seems to be exiftool. There is another tool called exif that is useful too, but it's difficult to set tags with just exif.
The software that runs my website depends on a couple of EXIF tags to successfully upload and resize a JPG. So I now needed to check the generated JPG and make sure these tags were set. Unfortunately they were not, but using exiftool it was easy to sort that.
First I found out the width and height of the new image in pixels using:
don@dipper ~ $ exiftool -H snowboarding.jpg | egrep -i "width|height"
- Image Width : 2068
- Image Height : 1478
With this information, the tags I require for for width and height are set with the following two commands:
don@dipper ~ $ exiftool -ExifImageWidth=2068 snowboarding.jpg
1 image files updated
don@dipper ~ $ exiftool -ExifImageHeight=1478 snowboarding.jpg
1 image files updated
Then I really thought it would be useful to back-date the 'original' date time of the image to reflect the fact it was an old photo. If the image was every index by an Android or Apple phone it should date it back in 1995 (or whatever). And certainly on my website it would be indexed correctly.
So the following command will back-date the jpg to 2001:
don@dipper ~ $ exiftool -dateTimeOriginal="2001:01:20 15:50" snowboarding.jpg
1 image files updated
Finally the following command use exif to display the set tags in hex and readable format. The hex format is useful because it is ultimate the hex codes that are common between different JPG readers and writers so this is the code that ultimately matter:
don@dipper ~ $ exif -i snowboarding.jpg
EXIF tags in 'snowboarding.jpg' ('Intel' byte order):
Tag |Value
0x00fe|0
0x0112|Top-left
0x011a|72
0x011b|72
0x0128|Inch
0x0131|GIMP 2.10.14
0x0132|2020:06:24 13:31:16
0x0100|256
0x0101|182
0x0102|8, 8, 8
0x0103|JPEG compression
0x0106|YCbCr
0x0115|3
0x011a|72
0x011b|72
0x0128|Inch
0x9003|2001:01:20 15:50:00
0xa001|sRGB
0xa002|2068
0xa003|1478
0x9000|Exif Version 2.1
0xa000|FlashPix Version 1.0
don@dipper ~ $ exif snowboarding.jpg
EXIF tags in 'snowboarding.jpg' ('Intel' byte order):
Tag |Value
New Subfile Type |0
Orientation |Top-left
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Software |GIMP 2.10.14
Date and Time |2020:06:24 13:31:16
Image Width |256
Image Length |182
Bits per Sample |8, 8, 8
Compression |JPEG compression
Photometric Interpre|YCbCr
Samples per Pixel |3
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time (Origi|2001:01:20 15:50:00
Colour Space |sRGB
Pixel X Dimension |2068
Pixel Y Dimension |1478
Exif Version |Exif Version 2.1
FlashPixVersion |FlashPix Version 1.0
EXIF data contains a thumbnail (7925 bytes).
The first two scanned photos
I have now scanned two photos (woo hoo!) just to get things working, which I thought I would share here and give the both a bit of context.
Photo 1 - Starting the West Highland Way in the summer of 1991
When | June 1991 |
Where | Milngavie, Scotland at the start of the West Highland Way |
Who | The 1st Largs Boys Brigade Company boys with section officers. |
What | It was the BB centenary year in 1992 when we had planned to make a special summer camp to France. To allow us to save for first ever camp abroad, we decided to walk the West Highland Way from Milngavie to Fort William over 90 miles away in 1991. This is the gang of boys who started the expedition which was an incredible experience for us all. We had everything - boys getting lost, torrential rain, a heat wave and injuries over six long days of walking. Looking back, we were so lucky to have the opportunity and the group of boys that did the walk were a complete laugh. I can still remember almost everyone's name. |
Photo 2 - Snowboarding at Les Deux Alpes, France
When | January 2000 |
Where | At a view point at the top of Les Deux Alpes |
Who | Me and friends |
What | This was my second ever snowboarding holiday abroad. Bob, Niel and I had celebrate the new millenium in Leeds just a few weeks before meeting up again for a really top holiday. There is no holiday to beat a snow holiday - the views, the boarding, the boozing and time outside. Really good times. |