Get EXIF ​​data without loading the whole image - Python

Is it possible to retrieve deleted EXIF ​​image information and download only EXIF ​​data?

From what I can understand about EXIF bytes in image files , EXIF ​​data is in the first few bytes of an image.

So the question is, how to load only the first few bytes of a remote file using Python? (Edit: relying on the HTTP range header is not enough, because not all remote hosts support it, in which case a full load will be performed.)

Is it possible, for example, to cancel a download after x bytes of progress?

+4
source share
2 answers

It depends a lot on the image format. For example, if you have a TIFF file, there is no a priori knowledge when EXIF ​​data, if any, is inside the file. It can be right after the heading and before the first IFD, but this is unlikely. This may be after image data. Most likely, it is somewhere in the middle.

If you need EXIF ​​information, extract it on the server (possibly a cache) and send it down, packed nicely, instead of requiring client code, do it.

+2
source

You can tell the web server that you are sending only portions of the file by setting the HTTP range header . See this answer for an example using urllib to partially download a file. This way you can load a piece, for example. 1000 bytes, check if the exif data is contained in the chunk and load more if you cannot find the exif app1 header or the exif data is incomplete.

+4
source

All Articles