Search code examples
pythonimportmoduleexif

Python exifread - Parsing difficulties


I'm trying to get the coordinates of a number of photos, i.e. I'm trying to get the exif data using a python script. The goal is to georeference all the photos and display their locations on a map. I am encountering problems with exif, however. I'm on Windows (64bit) and installed the corresponding (Strawberry) Perl software and then the Exiftool module (version 12.30) using Anaconda (Navigator), but to no avail. It gives me the following error: ModuleNotFoundError: No module named 'exif'. If I use the command pip install exif it tells me that the requirements are already met. What am I missing here? I'll gladly provide more information if required.

... I also tried an alternative: the module exifread works without import problems but does not seem to have all the necessary functionality (I can read the coordinates, but can't handle the extraction of the coordinates, it gives me a IfdTag-object when I would like an array of the degrees, minutes and seconds that I can then further process.)


Solution

  • There is a utility function exifread.utils.get_gps_coord() that provides convenient method to access coordinates as tuple in the format (latitude, longitude). Note negative value for latitude means South, negative value for longitude - West

    example

    import exifread
    path = 'image.jpg'
    with open(path, 'rb') as f:
        tags = exifread.process_file(f, details=False)
    
    coord = exifread.utils.get_gps_coords(tags)
    print(coord)
    

    For sake of completeness, there are also other modules to work with exif:

    Also, as mentioned in the comments - you can use ExifTool (Perl software), via subprocess