Search code examples
gimpgimpfu

Access exif data from gimpfu plugin


I am trying to access an images exif data from inside a gimpfu plugin, specifically the date a photo was taken, I can do this with PIL,

from PIL import Image

date_taken = Image.open(file)._getexif()[36867]

But when I try to import PIL, the plugin no longer appears inside the gimp menu. No error is being produced, and GIMP starts normally. Is there a way to get the exif data with gimpfu? Or is there a way to import PIL into the plugin?


Solution

  • If the plugin no longer appears in the Gimp menu, it is likely because there is some problem in it that prevents it from running to the end to register. It can be a syntax error or, in this case, a problem importing PIL. If you are on Linux or OSX this is easy to debug, just start Gimp in a terminal session, error messages from the python interpreter will be displayed there. On Windows you can start Gimp with a --verbose parameter to make it run with an additional console windows for messages, but I'm not sure the Python errors show up there. If they don't, bracket you whole code in a try/except and dump the Exception error to a file. You can use the traceback module to get more info (line number of error, etc) but it could itself be the cause of other import errors...

    To answer your initial problem, you can get the EXIF data from Gimp, using:

    exifData=image.parasite_find('exif-data').data
    

    However, this is just an array of bytes, and you have to do the parsing yourself (but I'll sure you'll find python code snippets to extract the data you want).