'How to read exif metadata from jpg file using only python, without any library?

I am trying to extract exif metadata from jpg file but hit a wall in between.

I am following this( https://www.w3.org/Graphics/JPEG/jfif3.pdf ) but not sure if it is the whole spec or not, if anyone one knows the whole spec please link me to it.

Although iam reading byte by byte:

with open("./image.jpg", "rb") as f:
    byte = f.read(2)
    while byte != b'':
        #byts.append(byte)
        if byte == b'\xff\xe1':
            byte = f.read(2)
            print(byte)
            data = f.read(214)
            print(data)

now it gives me something like this:

b'Exif\x00\x00MM\x00*\x00..... and so on

Can anyone please tell me how can i read all this data to seperate tag name and tag value?

I just want to do it without any library.

NOTE: basically this question is about how to read the jpg byte data to human readable string format



Solution 1:[1]

Others have linked you to the 190 page Exif manual however I strongly suggest you use the venerable cross platform EXIF command line tool, as it is easier to call that wheel than design your own one, and can be used on other files not just jpg.

To see the many ways it can be used for output play with the examples at https://exiftool.org/examples.html

enter image description here

so for a basic exif -common *.jpg the output pairs are very easy to parse

======== F218669077.jpg
File Name                       : F218669077.jpg
File Size                       : 102 KiB
Image Size                      : 800x789
======== pngtree-coffee-time-png-image_3626459.jpg
File Name                       : pngtree-coffee-time-png-image_3626459.jpg
File Size                       : 325 KiB
Image Size                      : 1200x1200
    2 image files read

Solution 2:[2]

You can use EXIF . Don't know much about it but it returns returs as a key:value pair.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Boblocaat