Search code examples
exifarcpy

How to use arcpy.GetImageEXIFProperties for more than one image at a time?


I used the function arcpy.GetImageEXIFProperties to read EXIF specific data from an image taken by a drone and it worked fine.

Now I have a bunch of pictures and tried the function for the folder containing all the images. It did not work.

Is there a way to make it work? Or is there a similar function that would do the trick for several images at once, instead of doing one image at a time?


Solution

  • arcpy.GetImageEXIFProperties expects a path to a single file. However, you could simply loop over the images within the folder.

    Following example loops over all images within the folder and its subfolders and adds the EXIF properties to a dictionary for future use:

    import arcpy
    from pathlib import Path
    
    IMAGE_FOLDER = Path(r"d:\backgrounds")
    
    exif_properties = {}
    
    for image in IMAGE_FOLDER.glob("**/*.jpg"):
        exif_properties[image.name] = arcpy.GetImageEXIFProperties(image)
    
    # print(exif_properties)
    print(exif_properties.get("luftaufnahme_winterthur.jpg"))
    

    (As far as I know, there is no ready-to-use function. If there would be one, that function would also loop over the files. You could add above code to a function for future reuse.)


    Caveat: Above code example does only work if file names are unique across the folder and its subfolders. Otherwise the last accessed file with the same name is added to the dictionary.

    If you don't want to include subfolders, simply change the pattern to *.jpg instead of **/*.jpg.