foto exif
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -32,9 +32,12 @@ 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
|
||||||
@@ -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
|
||||||
|
|||||||
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