From 93feae10262812239ea4aef269ac59463bbff319 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Mon, 5 Feb 2018 20:55:02 +0100 Subject: [PATCH] fix: Handle JPEGs identified as MPOs See details in https://github.com/python-pillow/Pillow/issues/1138 --- danube_delta/cli/photos.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/danube_delta/cli/photos.py b/danube_delta/cli/photos.py index 6c85761..a6d3944 100644 --- a/danube_delta/cli/photos.py +++ b/danube_delta/cli/photos.py @@ -81,13 +81,21 @@ def import_image(src_filename, dest_filename): click.echo('Saving: {}'.format(dest_filename)) options = dict(IMAGE_SAVE_OPTIONS) - if is_animated(image): + if is_animated_gif(image): options.setdefault('save_all', True) - image.save(dest_filename, image.format, **options) + image.save(dest_filename, get_format(image), **options) -def is_animated(image): - return len(list(ImageSequence.Iterator(image))) > 1 + +def is_animated_gif(image): + return ( + get_format(image) == 'GIF' and + len(list(ImageSequence.Iterator(image))) > 1 + ) + + +def get_format(image): + return 'JPEG' if image.format == 'MPO' else image.format def find_last_article(content_dir):