From 26b850d11f3b53961ec1a945c7ff39c54ba6ed56 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 29 Jun 2013 04:14:45 +0400 Subject: [PATCH] added exif rotation support to buildcache.py... Signed-off-by: Alex A. Naanou --- buildcache.py | 31 ++++++++++++++++++++++++++++++- scripts/process-archive.sh | 23 +++++++++++++++++------ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/buildcache.py b/buildcache.py index ea684adc..12eccdec 100755 --- a/buildcache.py +++ b/buildcache.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20130626175935''' +__sub_version__ = '''20130629041032''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -241,6 +241,8 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, verbosity=0): ''' absolute_path = config['absolute-path'] + orientation = None + for name in os.listdir(path): fname, ext = os.path.splitext(name) ext = ext[1:] @@ -251,6 +253,7 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, verbosity=0): source_path = pathjoin(path, name) raw = metadata.ImageMetadata(source_path) raw.read() + orientation = raw['Exif.Image.Orientation'] ##!!! can there be no previews? # get the biggest preview... preview = raw.previews[0] @@ -272,6 +275,12 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, verbosity=0): # normal images... elif ext == IMAGE: source_path = pathjoin(path, name) + meta = metadata.ImageMetadata(source_path) + meta.read() + if 'Exif.Image.Orientation' in meta: + orientation = meta['Exif.Image.Orientation'].value + else: + orientation = 0 # skip other files... else: @@ -282,6 +291,26 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, verbosity=0): 'name': name, 'type': 'image', 'state': 'single', + 'orientation': { + 1: 0, + 2: 0, + 3: 180, + 4: 0, + 5: 90, + 6: 90, + 7: 90, + 8: 270, + }[orientation], + 'flipped': { + 1: None, + 2: ['horizontal'], + 3: None, + 4: ['vertical'], + 5: ['vertical'], + 6: None, + 7: ['horizontal'], + 8: None, + }[orientation], 'path': getpath(path, source_path, absolute_path), 'ctime': os.path.getctime(pathjoin(path, name)), 'preview': {}, diff --git a/scripts/process-archive.sh b/scripts/process-archive.sh index f3c7a578..4c3c5d07 100755 --- a/scripts/process-archive.sh +++ b/scripts/process-archive.sh @@ -1,6 +1,6 @@ #!/bin/bash -ARCHIVE_ROOT="./20130501Y.001 - can be sfely deleted (2)" +ARCHIVE_ROOT="." METADATA_DIR="metadata" @@ -12,6 +12,11 @@ PREVIEW_NAME="%-:1d/${RAW_PREVIEW_DIR}/%f.jpg" JSON_NAME="%-:1d/${METADATA_DIR}/%f.json" +# TODO do a version of this using exiv2... +# - to be more flexible... +# - check speed... +# - give the user more options... +# # XXX need to also copy jpg originals to the preview dir (things that # were shot in jpeg in-camera)... @@ -19,12 +24,14 @@ JSON_NAME="%-:1d/${METADATA_DIR}/%f.json" # XXX need to prevent overwriting of unchanged exif data... # when file exists?? # XXX add PSD metadata extraction... +# -execute '-FileModifyDate