Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get EXIF data without downloading whole image - Python

Is is possible to get the EXIF information of an image remotely and with only downloading the EXIF data?

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

So the question is how to download only the first few bytes of a remote file, with Python? (Edit: Relying on HTTP Range Header is not good enough, as not all remote hosts support it, in which case full download will occur.)

Can I cancel the download after x bytes of progress, for example?

like image 334
knutole Avatar asked Dec 13 '12 14:12

knutole


People also ask

How do I get EXIF data from a photo?

On a Windows PC using File Explorer right-click on the file you want to see the data for. You will see a window pop up with various options. Click on Properties and then on Details. This will bring up the EXIF data for that photo.

What is EXIF Extractor?

Details. Retrieve Exif Data from image binary data. This extension can be used in page or logic actions, to retrieve stored Exif data from an image. The image binary can be presented as a parameter to one of the functions in the XIF.


2 Answers

You can tell the web server to only send you parts of a file by setting the HTTP range header. See This answer for an example using urllib to partially download a file. So you could download a chunk of e.g. 1000 bytes, check if the exif data is contained in the chunk, and download more if you can't find the exif app1 header or the exif data is incomplete.

like image 150
l4mpi Avatar answered Nov 14 '22 23:11

l4mpi


This depends on the image format heavily. For example, if you have a TIFF file, there is no knowing a priori where the EXIF data, if any, is within the file. It could be right after the header and before the first IFD, but this is unlikely. It could be way after the image data. Chances are it's somewhere in the middle.

If you want the EXIF information, extract that on the server (cache, maybe) and ship that down packaged up nicely instead of demanding client code do that.

like image 32
plinth Avatar answered Nov 14 '22 22:11

plinth