added exif rotation support to buildcache.py...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-06-29 04:14:45 +04:00
parent abc967b8c0
commit 26b850d11f
2 changed files with 47 additions and 7 deletions

View File

@ -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': {},

View File

@ -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<DateTimeOriginal' -tagsfromfile @ \
# -srcfile "$PROCESSED_PREVIEW_NAME" -overwrite_original \
# XXX keep file dates...
exiftool -if '$jpgfromraw' -b -jpgfromraw -w "$PREVIEW_NAME" \
-execute -if '$previewimage' -b -previewimage -w "$PREVIEW_NAME" \
-execute '-FileModifyDate<DateTimeOriginal' -tagsfromfile @ -srcfile "$PREVIEW_NAME" -overwrite_original \
-execute '-FileModifyDate<DateTimeOriginal' -tagsfromfile @ -srcfile "$PROCESSED_PREVIEW_NAME" -overwrite_original \
-execute '-FileModifyDate<DateTimeOriginal' -tagsfromfile @ \
-srcfile "$PREVIEW_NAME" -overwrite_original \
-execute -j -w "$JSON_NAME" \
-common_args --ext jpg -r "$ARCHIVE_ROOT" -progress
@ -33,7 +40,7 @@ SIZE=900
COMPRESSION=90
PATH=$PATH:`pwd`/vips-dev-7.32.0/bin/
PATH=$PATH:/mnt/d/Program\ Files/vips/bin/
# makepreview SIZE IN OUT
makepreview(){
@ -70,10 +77,14 @@ makepreview(){
# XXX use find...
for FROM in "${ARCHIVE_ROOT}"/DCIM/hi-res\ \(RAW\)/*jpg ; do
cd "${ARCHIVE_ROOT}"
for FROM in */DCIM/hi-res\ \(RAW\)/*jpg ; do
TO="${FROM/hi-res\ /preview }"
# XXX do different-sized previews...
makepreview "$SIZE" "$FROM" "$TO"
makepreview "$SIZE" "./$FROM" "$TO"
done
# vim:set nowrap nospell :