foto exif
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -32,10 +32,13 @@ 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
|
||||
process :resize_to_fill => [64, 64]
|
||||
@@ -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
|
||||
|
||||
6
db/migrate/20150401111040_add_exif_to_foto.rb
Normal file
6
db/migrate/20150401111040_add_exif_to_foto.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddExifToFoto < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :fotos, :exif, :string
|
||||
add_column :fotos, :has_exif, :boolean
|
||||
end
|
||||
end
|
||||
5
db/migrate/20150401115254_add_date_to_foto.rb
Normal file
5
db/migrate/20150401115254_add_date_to_foto.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddDateToFoto < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :fotos, :taken_at, :timestamp
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user