Quote:
Originally Posted by kovidgoyal
Merged, removing the check for .jpg in the URL since if imghdr fails to identify the image type, it is coerced to jpeg anyway.
|
Not true--in my testing imghdr returned 'None' for some large jpegs. Look at the flow: None goes right past the tests.
Code:
if itype not in {'png', 'jpg', 'jpeg'}:
itype = 'png' if itype == 'gif' else 'jpg'
im = Image()
im.load(data)
data = im.export(itype)
if self.compress_news_images and itype in {'jpg','jpeg'}:
try:
data = self.rescale_image(data)
except:
self.log.exception('failed to compress image '+iurl)
identify_data(data)
else:
identify_data(data)
EDIT: I take that back--None should drop into the first, but in my testing it did not (??). Does None automatically fail the 'in' test?
2ND EDIT: OK I checked using the Python interpreter and itype being None will get snagged and coerced to jpeg, so I'll assume I mistook what was happening in the fog of debugging!