|
|
|
|
@ -70,8 +70,11 @@ def generate_image(source, outname, settings, options=None):
|
|
|
|
|
utils.copy(source, outname, symlink=settings['orig_link']) |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
img = PILImage.open(source) |
|
|
|
|
original_format = img.format |
|
|
|
|
with warnings.catch_warnings(record = True) as caught_warnings: |
|
|
|
|
img = PILImage.open(source) |
|
|
|
|
original_format = img.format |
|
|
|
|
|
|
|
|
|
_handle_caught_warnings(caught_warnings, source) |
|
|
|
|
|
|
|
|
|
if settings['copy_exif_data'] and settings['autorotate_images']: |
|
|
|
|
logger.warning("The 'autorotate_images' and 'copy_exif_data' settings " |
|
|
|
|
@ -120,8 +123,11 @@ def generate_thumbnail(source, outname, box, delay, fit=True, options=None):
|
|
|
|
|
"""Create a thumbnail image.""" |
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
img = PILImage.open(source) |
|
|
|
|
original_format = img.format |
|
|
|
|
with warnings.catch_warnings(record = True) as caught_warnings: |
|
|
|
|
img = PILImage.open(source) |
|
|
|
|
original_format = img.format |
|
|
|
|
|
|
|
|
|
_handle_caught_warnings(caught_warnings, source) |
|
|
|
|
|
|
|
|
|
if fit: |
|
|
|
|
img = ImageOps.fit(img, box, PILImage.ANTIALIAS) |
|
|
|
|
@ -170,7 +176,11 @@ def process_image(filepath, outpath, settings):
|
|
|
|
|
def get_size(file_path): |
|
|
|
|
"""Return image size (width and height).""" |
|
|
|
|
try: |
|
|
|
|
im = PILImage.open(file_path) |
|
|
|
|
with warnings.catch_warnings(record = True) as caught_warnings: |
|
|
|
|
im = PILImage.open(file_path) |
|
|
|
|
|
|
|
|
|
_handle_caught_warnings(caught_warnings, file_path) |
|
|
|
|
|
|
|
|
|
except (IOError, IndexError, TypeError, AttributeError) as e: |
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
logger.error("Could not read size of %s due to %r", file_path, e) |
|
|
|
|
@ -191,7 +201,11 @@ def get_exif_data(filename):
|
|
|
|
|
warnings.warn('Pillow 3.0.0 is broken with EXIF data, consider using ' |
|
|
|
|
'another version if you want to use EXIF data.') |
|
|
|
|
|
|
|
|
|
img = PILImage.open(filename) |
|
|
|
|
with warnings.catch_warnings(record = True) as caught_warnings: |
|
|
|
|
img = PILImage.open(filename) |
|
|
|
|
|
|
|
|
|
_handle_caught_warnings(caught_warnings, filename) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
exif = img._getexif() or {} |
|
|
|
|
except ZeroDivisionError: |
|
|
|
|
@ -312,3 +326,14 @@ def get_exif_tags(data):
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return simple |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _handle_caught_warnings(caught_warnings, filename): |
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
for warning in caught_warnings: |
|
|
|
|
if warning.category == PILImage.DecompressionBombWarning: |
|
|
|
|
logger.info('PILImage reported a possible DecompressionBomb' |
|
|
|
|
' for file {}'.format(filename)) |
|
|
|
|
else: |
|
|
|
|
warnings.showwarning(warning.message, warning.category, |
|
|
|
|
warning.filename, warning.lineno) |