Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Rename pictures according to their exif information, taking sequence number into account
#!/usr/bin/env python
# encoding: utf-8
pict-exif-rename: Rename pictures according to their exif information, taking
sequence number into account.
This relies on the presence of the Exif.Panasonic.SequenceNumber tag, so may
not work with all cameras.
Author: Aurélien Gâteau <>
License: GPLv3+
import os
import sys
from optparse import OptionParser
import pyexiv2
USAGE = "%prog [options] <pict1> [<pict2>...]"
def name_from_metadata(image_name):
adir = os.path.dirname(image_name)
metadata = pyexiv2.ImageMetadata(image_name)
date_tag = metadata['Exif.Photo.DateTimeOriginal']
sequence_tag = metadata['Exif.Panasonic.SequenceNumber']
new_name = date_tag.value.strftime("%Y-%m-%d_%H-%M-%S")
sequence = sequence_tag.value
if sequence > 0:
new_name += "-n%03d" % sequence
new_name += ".jpg"
return os.path.join(adir, new_name)
def main():
parser = OptionParser(usage=USAGE)
action="store_true", dest="dry_run", default=False,
help="Dry run, print what would be done")
(options, args) = parser.parse_args()
if len(args) < 1:
parser.error("Missing args")
for name in args:
new_name = name_from_metadata(name)
if new_name == name:
print "%s: no change" % name
print "%s: -> %s" % (name, new_name)
if not options.dry_run:
assert not os.path.exists(new_name)
os.rename(name, new_name)
return 0
if __name__ == "__main__":
# vi: ts=4 sw=4 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.