From 1b2440f68a7208c14aaec6243da2bb9f6ced4e98 Mon Sep 17 00:00:00 2001
From: Maxwell Salzberg <maxwell@joindiaspora.com>
Date: Fri, 20 Apr 2012 12:22:12 -0700
Subject: [PATCH] we now store image height and width locally; still need to
 federate the values

---
 app/uploaders/unprocessed_image.rb                     |  8 +++++++-
 .../20120420185823_add_width_and_height_to_photos.rb   |  6 ++++++
 db/schema.rb                                           |  4 +++-
 spec/models/photo_spec.rb                              | 10 ++++++++++
 4 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 db/migrate/20120420185823_add_width_and_height_to_photos.rb

diff --git a/app/uploaders/unprocessed_image.rb b/app/uploaders/unprocessed_image.rb
index 895f45167a..bc6f520c14 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 0000000000..ebe77913e8
--- /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 5dbac0d3f4..e4750fb052 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 dbb2b07877..9bcdd50fb4 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
-- 
GitLab