foto exif

This commit is contained in:
Andreas Stephanides
2015-04-07 23:19:27 +02:00
parent bd7aac9bb7
commit b04b23e647
4 changed files with 27 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ class Foto < ActiveRecord::Base
attr_accessible :datei, :desc, :gallery_id, :title attr_accessible :datei, :desc, :gallery_id, :title
belongs_to :gallery belongs_to :gallery
mount_uploader :datei, FotoUploader mount_uploader :datei, FotoUploader
before_save :parse_exif
resourcify resourcify
def to_jq_upload def to_jq_upload
{ {
@@ -28,4 +29,11 @@ class Foto < ActiveRecord::Base
"delete_type" => "DELETE" "delete_type" => "DELETE"
} }
end 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 end

View File

@@ -32,10 +32,13 @@ class FotoUploader < CarrierWave::Uploader::Base
# end # end
# general settings # general settings
process :fix_exif_rotation process :fix_exif_rotation
process :store_exif
process :strip process :strip
process :convert => 'jpg' process :convert => 'jpg'
# Create different versions of your uploaded files: # Create different versions of your uploaded files:
version :thumb do version :thumb do
process :resize_to_fill => [64, 64] process :resize_to_fill => [64, 64]
@@ -62,5 +65,9 @@ class FotoUploader < CarrierWave::Uploader::Base
# "something.jpg" if original_filename # "something.jpg" if original_filename
# end # end
def store_exif
img = Magick::Image.read(current_path)
model.exif=img.first.get_exif_by_entry().to_json
end
end end

View File

@@ -0,0 +1,6 @@
class AddExifToFoto < ActiveRecord::Migration
def change
add_column :fotos, :exif, :string
add_column :fotos, :has_exif, :boolean
end
end

View File

@@ -0,0 +1,5 @@
class AddDateToFoto < ActiveRecord::Migration
def change
add_column :fotos, :taken_at, :timestamp
end
end