diff --git a/app/models/foto.rb b/app/models/foto.rb index cbe9761..b8895c9 100644 --- a/app/models/foto.rb +++ b/app/models/foto.rb @@ -15,6 +15,7 @@ class Foto < ActiveRecord::Base attr_accessible :datei, :desc, :gallery_id, :title belongs_to :gallery mount_uploader :datei, FotoUploader + before_save :parse_exif resourcify def to_jq_upload { @@ -28,4 +29,11 @@ class Foto < ActiveRecord::Base "delete_type" => "DELETE" } end + def parse_exif + unless self.exif.nil? || self.exif.empty? + j=JSON.parse(self.exif) + datetime = j.select {|i| i.first == "DateTime"}.try(:first).try(:last) + self.taken_at=Time.new(datetime) unless datetime.nil? + end + end end diff --git a/app/uploaders/foto_uploader.rb b/app/uploaders/foto_uploader.rb index 1a2385d..5058f26 100644 --- a/app/uploaders/foto_uploader.rb +++ b/app/uploaders/foto_uploader.rb @@ -32,9 +32,12 @@ class FotoUploader < CarrierWave::Uploader::Base # end # general settings + process :fix_exif_rotation + process :store_exif process :strip process :convert => 'jpg' + # Create different versions of your uploaded files: version :thumb do @@ -62,5 +65,9 @@ class FotoUploader < CarrierWave::Uploader::Base # "something.jpg" if original_filename # end - + def store_exif + img = Magick::Image.read(current_path) + model.exif=img.first.get_exif_by_entry().to_json + + end end diff --git a/db/migrate/20150401111040_add_exif_to_foto.rb b/db/migrate/20150401111040_add_exif_to_foto.rb new file mode 100644 index 0000000..ab63cea --- /dev/null +++ b/db/migrate/20150401111040_add_exif_to_foto.rb @@ -0,0 +1,6 @@ +class AddExifToFoto < ActiveRecord::Migration + def change + add_column :fotos, :exif, :string + add_column :fotos, :has_exif, :boolean + end +end diff --git a/db/migrate/20150401115254_add_date_to_foto.rb b/db/migrate/20150401115254_add_date_to_foto.rb new file mode 100644 index 0000000..f25b2c7 --- /dev/null +++ b/db/migrate/20150401115254_add_date_to_foto.rb @@ -0,0 +1,5 @@ +class AddDateToFoto < ActiveRecord::Migration + def change + add_column :fotos, :taken_at, :timestamp + end +end