View Single Post
Old 03-17-2013, 10:56 AM   #6
nickredding
onlinenewsreader.net
nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'
 
Posts: 328
Karma: 10143
Join Date: Dec 2009
Location: Phoenix, AZ & Victoria, BC
Device: Kindle 3, Kindle Fire, IPad3, iPhone4, Playbook, HTC Inspire
Quote:
Originally Posted by kovidgoyal View Post
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!

Last edited by nickredding; 03-17-2013 at 07:21 PM.
nickredding is offline   Reply With Quote