Search code examples
ruby-on-railsimagemagickexifminimagick

How to get EXIF keywords using mini_magick in a Rails app?


I am attempting to pull the EXIF information for images that have values for the EXIF "keywords" attribute. I have successfully read EXIF information using mini_magick by simply opening an image and using:

image["EXIF:Model"]

For some reason, none of the following will return keywords for an image that I know has them:

image["EXIF:Keywords"]
image["EXIF:XPKeywords"]
image["EXIF:Subject"]

I have confirmed that the image in question does have this information using this utility: http://regex.info/exif.cgi

Does mini_magick only have access to certain EXIF values? It seems so odd that I can access certain EXIF information but not others.


Solution

  • EXIF metadata is created by camera, therefore it contains only technical related stuff. What you actually want to access is IPTC and XMP.

    Imagemagick, which is behind mini_magick, allows to read IPTC, e.g. image["%[IPTC:2:25]"] for keywords (update: be aware of perfomance issues, see comments).

    As for XMP, I don't know an easy way to do this. You can try to run

    `identify -verbose #{your_filename}`
    

    and then grub lines that include xmp.