diff --git a/app/uploaders/unprocessed_image.rb b/app/uploaders/unprocessed_image.rb index 895f45167ae9ab28c16f30d9c94d48f1f58697db..bc6f520c1442f52daa99319c0eb157dd9eb37be6 100644 --- a/app/uploaders/unprocessed_image.rb +++ b/app/uploaders/unprocessed_image.rb @@ -20,5 +20,11 @@ class UnprocessedImage < CarrierWave::Uploader::Base version :thumb_small version :thumb_medium version :thumb_large - version :scaled_full + version :scaled_full do + process :get_version_dimensions + end + + def get_version_dimensions + model.width, model.height = `identify -format "%wx%h" #{file.path}`.split(/x/) + end end diff --git a/db/migrate/20120420185823_add_width_and_height_to_photos.rb b/db/migrate/20120420185823_add_width_and_height_to_photos.rb new file mode 100644 index 0000000000000000000000000000000000000000..ebe77913e83341e6f945e4b5ce5c9d98f4bf0a03 --- /dev/null +++ b/db/migrate/20120420185823_add_width_and_height_to_photos.rb @@ -0,0 +1,6 @@ +class AddWidthAndHeightToPhotos < ActiveRecord::Migration + def change + add_column :photos, :height, :integer + add_column :photos, :width, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5dbac0d3f4dc046a431dcfead189a336a98fe185..e4750fb052f2b6a21d20dbbf09700d59e319dd9c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120414005431) do +ActiveRecord::Schema.define(:version => 20120420185823) do create_table "account_deletions", :force => true do |t| t.string "diaspora_handle" @@ -297,6 +297,8 @@ ActiveRecord::Schema.define(:version => 20120414005431) do t.string "unprocessed_image" t.string "status_message_guid" t.integer "comments_count" + t.integer "height" + t.integer "width" end add_index "photos", ["status_message_guid"], :name => "index_photos_on_status_message_guid" diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index dbb2b0787778c93f1f7dc4104460d191bea2985e..9bcdd50fb44106874f9fa5c2e029e746cc92629d 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -125,7 +125,11 @@ describe Photo do context 'with a saved photo' do before do + UnprocessedImage.enable_processing = true + @photo.unprocessed_image.store! File.open(@fixture_name) + UnprocessedImage.enable_processing = false + end it 'should have text' do @photo.text= "cool story, bro" @@ -145,6 +149,12 @@ describe Photo do @photo.url.include?(@fixture_filename).should be false @photo.url(:thumb_medium).include?("/" + @fixture_filename).should be false end + + it 'should save the image dimensions' do + + @photo.width.should == 40 + @photo.height.should == 40 + end end describe 'non-image files' do