Determining the size of a JPEG (JFIF) image

后端 未结 4 1204
北荒
北荒 2020-12-23 14:36

I need to find the size of a JPEG (JFIF) image. The image is not saved as a stand-alone file, so I can\'t use GetFileSize or any other API such this one (the im

4条回答
  •  执笔经年
    2020-12-23 14:50

    In python, you could just read the whole file into a string object and find the first occurrence of FF E0 and the last occurrence of FF D9. Presumably, these are the start and end that you are looking for?

    f = open("filename.jpg", "r")
    s = f.read()
    start = s.find("\xff\xe0")
    end = s.rfind("\xff\xd9")
    imagesize = end - start
    

提交回复
热议问题