made extracting orientation optional...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-06-29 04:22:53 +04:00
parent 26b850d11f
commit 045a83ad96

View File

@ -1,7 +1,7 @@
#======================================================================= #=======================================================================
__version__ = '''0.0.01''' __version__ = '''0.0.01'''
__sub_version__ = '''20130629041032''' __sub_version__ = '''20130629042157'''
__copyright__ = '''(c) Alex A. Naanou 2011''' __copyright__ = '''(c) Alex A. Naanou 2011'''
@ -30,6 +30,7 @@ import gid
CONFIG = { CONFIG = {
'absolute-path': False, 'absolute-path': False,
'ignore-orientation': False,
# this can be: # this can be:
# - original (default) # - original (default)
@ -241,7 +242,7 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, verbosity=0):
''' '''
absolute_path = config['absolute-path'] absolute_path = config['absolute-path']
orientation = None orientation = 0
for name in os.listdir(path): for name in os.listdir(path):
fname, ext = os.path.splitext(name) fname, ext = os.path.splitext(name)
@ -272,15 +273,19 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, verbosity=0):
raw.copy(preview) raw.copy(preview)
preview.write() preview.write()
if not config['ignore-orientation']:
if 'Exif.Image.Orientation' in raw:
orientation = raw['Exif.Image.Orientation'].value
# normal images... # normal images...
elif ext == IMAGE: elif ext == IMAGE:
source_path = pathjoin(path, name) source_path = pathjoin(path, name)
meta = metadata.ImageMetadata(source_path)
meta.read() if not config['ignore-orientation']:
if 'Exif.Image.Orientation' in meta: meta = metadata.ImageMetadata(source_path)
orientation = meta['Exif.Image.Orientation'].value meta.read()
else: if 'Exif.Image.Orientation' in meta:
orientation = 0 orientation = meta['Exif.Image.Orientation'].value
# skip other files... # skip other files...
else: else:
@ -534,6 +539,11 @@ def handle_commandline():
action='store_true', action='store_true',
default=False, default=False,
help='Create only images.json file, skip the rest.') help='Create only images.json file, skip the rest.')
output_configuration.add_option('--ignore-orientation',
action='store_true',
default=False,
help='Ignore EXIF orientation data -- when previews '
'are already in correct orientation.')
output_configuration.add_option('--path-mode', output_configuration.add_option('--path-mode',
default='absolute' if CONFIG['absolute-path'] else 'relative', default='absolute' if CONFIG['absolute-path'] else 'relative',
help='Path generation mode (default: "%default").') help='Path generation mode (default: "%default").')
@ -599,6 +609,7 @@ def handle_commandline():
config.update({ config.update({
'gid-source': options.gid_source, 'gid-source': options.gid_source,
'absolute-path': options.path_mode == 'absolute', 'absolute-path': options.path_mode == 'absolute',
'ignore-orientation': options.ignore_orientation,
}) })
# a value from 0 through 2... # a value from 0 through 2...
verbosity = options.verbosity verbosity = options.verbosity