Get EXIF data without downloading whole image - Python

久未见 提交于 2019-12-10 14:26:08

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13861581/get-exif-data-without-downloading-whole-image-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!