public
Rubygem
Description: A lightweight and opinionated but hackable library for attaching images to ActiveRecord models.
Homepage:
Clone URL: git://github.com/norman/has_image.git
use width/height columns to store dimensions if they’re present in the model
Gerrit Kaiser (author)
Tue Oct 21 23:55:08 -0700 2008
commit  d7b057604aa0399afd51c89c3199644b860a2aea
tree    4130a8d2ba3685963f48c5b3fa0696bd782c078b
parent  fb9a4d609387f8e33151042bbca0e0d1f812db83
...
170
171
172
173
 
174
175
176
177
 
178
179
180
...
210
211
212
213
 
214
215
216
217
218
219
 
220
221
 
 
 
 
 
 
 
 
222
223
224
...
170
171
172
 
173
174
175
176
 
177
178
179
180
...
210
211
212
 
213
214
215
216
217
218
 
219
220
221
222
223
224
225
226
227
228
229
230
231
232
0
@@ -170,11 +170,11 @@ module HasImage
0
     end
0
     
0
     def width
0
-      minimagick[:width]
0
+      self[:width] || minimagick[:width]
0
     end
0
     
0
     def height
0
-      minimagick[:height]
0
+      self[:height] || minimagick[:height]
0
     end
0
     
0
     def minimagick
0
@@ -210,15 +210,23 @@ module HasImage
0
     def update_images
0
       return if storage.temp_file.blank?
0
       remove_images
0
-      update_attribute(has_image_options[:column], storage.install_images(self))
0
+      populate_attributes
0
     end
0
 
0
     # Processes and installs the image and its thumbnails.
0
     def install_images
0
       return if !storage.temp_file
0
-      update_attribute(has_image_options[:column], storage.install_images(self))
0
+      populate_attributes
0
     end
0
     
0
+    def populate_attributes
0
+      send("#{has_image_options[:column]}=", storage.install_images(self))
0
+      self[:width] = minimagick[:width] if self.class.column_names.include?('width')
0
+      self[:height] = minimagick[:height] if self.class.column_names.include?('height')
0
+      save!
0
+    end
0
+    private :populate_attributes
0
+    
0
     # Gets an instance of the underlying storage functionality. See
0
     # HasImage::Storage.
0
     def storage
...
26
27
28
29
 
 
 
30
31
32
...
26
27
28
 
29
30
31
32
33
34
0
@@ -26,7 +26,9 @@ module HasImage
0
           `identify #{arg.respond_to?(:path) ? arg.path : arg.to_s}`
0
           $? == 0
0
         end
0
-      end    
0
+      end
0
+      
0
+      
0
     end
0
 
0
     # The constuctor should be invoked with the options set by has_image.
...
5
6
7
8
 
 
 
 
 
 
 
9
...
5
6
7
 
8
9
10
11
12
13
14
15
0
@@ -5,5 +5,11 @@ ActiveRecord::Schema.define(:version => 1) do
0
     t.datetime :created_at
0
     t.datetime :updated_at
0
   end
0
-
0
+  
0
+  create_table 'complex_pics', :force => true do |t|
0
+    t.string :filename
0
+    t.integer :width, :height
0
+    t.timestamps
0
+  end
0
+  
0
 end

Comments