Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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 <aurelien.gateau@free.fr>
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)
metadata.read()
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)
parser.add_option("--dry-run",
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
else:
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__":
sys.exit(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.