I make an album with pictures from several friends' cameras. Let's imagine that the EXIF exposure date and time are correct in all files. Filenames, however, are not aligned (e.g. my camera starts at IMG0001 but my friend's phone camera starts at pic1234.jpg, and my own phone starts at pic5678.jpg).
Is there a way with Shotwell to export the files from everyone over to a plain directory, with the filenames rewritten so that the pictures are sorted in chronological order? Then, when I slideshow these files in another computer, with another image viewer (or with Shotwell itself in file browsing mode), they will show in the right chronological order.
Example. If I have these six files...
- My camera: IMG_0001.JPG - EXIF exposure date 2012/12/25 12:05:00
- My camera: IMG_0002.JPG - EXIF exposure date 2012/12/25 12:11:00
- My own phone: pic5678.jpg - EXIF exposure date 2012/12/25 12:09:00
- My own phone: pic5679.jpg - EXIF exposure date 2012/12/25 12:15:00
- Friend's phone: pic1234.jpg - EXIF exposure date 2012/12/25 12:08:00
- Friend's phone: pic1235.jpg - EXIF exposure date 2012/12/25 12:18:00
...then I would like to export them with filenames like these:
- 20121225_120500-IMG_0001.JPG
- 20121225_120800-pic1234.jpg
- 20121225_120900-pic5678.jpg
- 20121225_121100-IMG_0002.JPG
- 20121225_121500-pic5679.jpg
- 20121225_121800-pic1235.jpg
so that they show in the right order when browsing with any image browser.
The following script does the trick, but is not integrated in Shotwell, which is the point of the question, and will (gracefully) fail if the pictures are not exported with Exif data:
#!/usr/bin/python
import pyexiv2
import sys
import shutil
def getTimestamp(f):
metadata = pyexiv2.ImageMetadata(f)
metadata.read()
try:
d = metadata['Exif.Image.DateTime']
return d.value.strftime('%Y%m%d%H%M%S')
except Exception as e:
return "00000000000000"
if len(sys.argv) > 1:
for f in sys.argv[1:]:
try:
timestamp = getTimestamp(f)
prefix = "%s_" % timestamp
if f[0:len(prefix)] == prefix:
print "File %s was already renamed, not renaming again" % (f)
else:
nn = "%s%s" % (prefix, f)
shutil.move(f, nn)
print "File %s renamed to %s" % (f, nn)
except Exception as e:
print "File %s not renamed (%s)" % (f, e)
else:
print "Usage: %s <JPG files with Exif tags>" % (sys.argv[0])