TNThieding/exif

Exception IOError("EXIF APP1 segment not found") raised when opening an image without EXIF

Closed this issue · 5 comments

Greetings!

It's a great library! However, it seems that when I'm trying to open an image that doesn't contain EXIF I'm getting IOError("EXIF APP1 segment not found") exception.

It is an issue since I'm trying to process a number of files where only some of them have EXIF data. It would be great to handle non-EXIF images without throwing an exception as this is a quite expensive operation and in my case will have a significant impact on performance.

Or am I missing something and there is a recommended way to handle images without EXIF?

Thank you for reaching out. Currently, users must use a try/except block as you mentioned above. Do you have any suggestions for a different way of handling this use case? I'd love to get your perspective and hear your use case as a user of the library.

Hi Tyler,

My use case is this: I analyze thousands, potentially tens of thousands of images a day, stored in S3 bucket. Extracting data from Exif is one of the steps in this analysis. Some of those images, potentially all of them, uploaded on a given day, might not have an Exif. This means that I need to consider the handling of an image without Exif as a normal flow in my application rather than the exception, as it could become quite expensive. In terms of execution time but in the case of AWS also quite literally.

I'm coming from the .NET world and only writing in Python in the last 6 months or so, therefore I don't feel comfortable to suggest any solution that would be a clean pythonic way. From my simplistic perspective Image() could succeed just fine and then dir() would return an empty list in case of such an image.

there is no need to worry about the cost of exceptions for python code (a good discussion is here https://softwareengineering.stackexchange.com/questions/351110/are-exceptions-for-flow-control-best-practice-in-python ).

Thanks for that! The post you quoted provides an in-depth explanation, so thanks again for the link. I'm taking that exception catching in Python is not as expensive. However, in this post the timings (and some answers) indicate a significant overhead when catching the exception vs if-else statement.

I just released version 0.8.0 of the package (see https://gitlab.com/TNThieding/exif/merge_requests/21) which adds the has_exif attribute and removes the IOError exceptions. Don't hesitate to follow-up with an additional issue if necessary.