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
moved measuring into the processor where it belongs
Gerrit Kaiser (author)
Wed Oct 22 00:09:10 -0700 2008
commit  59f7224fcb6bb6bd8f170dc9cb00d57af04d33db
tree    e1ec3a318106a8c5022aab419f44da25cd000c71
parent  d7b057604aa0399afd51c89c3199644b860a2aea
...
170
171
172
173
 
174
175
176
177
 
178
179
180
181
182
183
184
185
186
187
...
221
222
223
224
225
 
 
226
227
228
...
170
171
172
 
173
174
175
176
 
177
178
179
 
 
 
 
 
180
181
182
...
216
217
218
 
 
219
220
221
222
223
0
@@ -170,18 +170,13 @@ module HasImage
0
     end
0
     
0
     def width
0
-      self[:width] || minimagick[:width]
0
+      self[:width] || storage.measure(absolute_path, :width)
0
     end
0
     
0
     def height
0
-      self[:height] || minimagick[:height]
0
+      self[:height] || storage.measure(absolute_path, :height)
0
     end
0
     
0
-    def minimagick
0
-      MiniMagick::Image.from_file(absolute_path)
0
-    end
0
-    private :minimagick
0
-    
0
     def image_size
0
       [width, height] * 'x'
0
     end
0
@@ -221,8 +216,8 @@ module HasImage
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
+      self[:width] = storage.measure(absolute_path, :width) if self.class.column_names.include?('width')
0
+      self[:height] = storage.measure(absolute_path, :height) if self.class.column_names.include?('height')
0
       save!
0
     end
0
     private :populate_attributes
...
28
29
30
31
32
33
34
...
55
56
57
 
 
 
 
 
58
59
60
...
28
29
30
 
31
32
33
...
54
55
56
57
58
59
60
61
62
63
64
0
@@ -28,7 +28,6 @@ module HasImage
0
         end
0
       end
0
       
0
-      
0
     end
0
 
0
     # The constuctor should be invoked with the options set by has_image.
0
@@ -55,6 +54,11 @@ module HasImage
0
     end
0
     alias_method :resize, :process #Backwards-compat
0
     
0
+    # Gets the given +dimension+ (width/height) from the image file at +path+
0
+    def measure(path, dimension)
0
+      MiniMagick::Image.from_file(path)[dimension.to_sym]
0
+    end
0
+    
0
   private
0
     # operate on the image with MiniMagick
0
     # yields a MiniMagick::Image object
...
91
92
93
 
 
 
 
 
94
95
96
...
91
92
93
94
95
96
97
98
99
100
101
0
@@ -91,6 +91,11 @@ module HasImage
0
       @temp_file = nil
0
     end
0
     
0
+    # Measures the given dimension using the processor
0
+    def measure(path, dimension)
0
+      processor.measure(path, dimension)
0
+    end
0
+    
0
     # Gets the "web" path for an image. For example:
0
     #
0
     #   /photos/0000/0001/3er0zs.jpg

Comments