def load_exif
exif_img = EXIFR::JPEG.new(image.queued_for_write[:custom].path)
if !exif_img.gps.nil?
self.latitude = exif_img.gps.latitude
self.longitude = exif_img.gps.longitude
end
end
For my project I have a Post model correlating to the table "posts" in the database. In my Post model I defined a method that uses the EXIFR Gem to access the image metadata.In this case the path to the image (in this case "image" is the name of the database column we defined using Paperclip) is passed to the EXIFR Gem, stored in the the exif_img variable and then the GPS data is passed to the database using Active Record methods. The method load_exif is called after the image is processed:
after_image_post_process :load_exif
Using binding.pry to inspect the exif_img variable containing nested arrays and hashes is quite impressive:
View the project on Github: https://github.com/dtothefp/dylanthedog

No comments:
Post a Comment