I use rmagick when it comes to deal with images. I’m not that disappointed like Zed Shaw with rmagick (but Zed is totally right when he points out on page 4: “[…] and is difficult to install (unless your computer is nearly exactly the same as the author’s).”), but when it comes to deal with EXIF, rmagick sucks big time.
After some searching i found another EXIF reader called “EXIF Reader” (EXIFR), which can be downloaded and installed from here or via gems.
I came mainly to this point becaus rmagick completly failed reading GPS data from my images (and it is hard to use with all other values).
EXIFR on the contrast cannot do image manipulation, so i needed both. Maybe i’m still just to new to ruby, but exifr gave me a hard time not reading the same image twice from file, once for rmagick and once for exifr.
I came up with the following solution:
require 'rubygems' require 'RMagick' require 'exifr' image = Magick::ImageList.new("whatever_image.jpg") exif_info = case image.format when 'JPEG' EXIFR::JPEG.new(StringIO.new(image.to_blob)) when 'TIFF' EXIFR::TIFF.new(StringIO.new(image.to_blob)) else nil end
This uses rmagick to instantiate a magick image and then a StringIO object to build up the exif information if the image is a jpeg or a tiff image.