Commit ffcd39dc

mo khan <mo@mokhan.ca>
2014-06-08 03:51:25
rename variables.
1 parent dd1277b
Changed files (1)
app
services
infrastructure
app/services/infrastructure/image.rb
@@ -24,36 +24,36 @@ class Image
   end
 
   def resize_to_fit(width:, height:)
-    manipulate! do |img|
-      img.resize "#{width}x#{height}"
-      img = yield(img) if block_given?
-      img
+    manipulate! do |image|
+      image.resize "#{width}x#{height}"
+      image = yield(image) if block_given?
+      image
     end
   end
 
   def resize_to_fill(width:, height:, gravity: 'Center')
-    manipulate! do |img|
-      cols, rows = img[:dimensions]
-      img.combine_options do |cmd|
-        if width != cols || height != rows
-          scale_x = width/cols.to_f
+    manipulate! do |image|
+      columns, rows = image[:dimensions]
+      image.combine_options do |cmd|
+        if width != columns || height != rows
+          scale_x = width/columns.to_f
           scale_y = height/rows.to_f
           if scale_x >= scale_y
-            cols = (scale_x * (cols + 0.5)).round
+            columns = (scale_x * (columns + 0.5)).round
             rows = (scale_x * (rows + 0.5)).round
-            cmd.resize "#{cols}"
+            cmd.resize "#{columns}"
           else
-            cols = (scale_y * (cols + 0.5)).round
+            columns = (scale_y * (columns + 0.5)).round
             rows = (scale_y * (rows + 0.5)).round
             cmd.resize "x#{rows}"
           end
         end
         cmd.gravity gravity
         cmd.background "rgba(255,255,255,0.0)"
-        cmd.extent "#{width}x#{height}" if cols != width || rows != height
+        cmd.extent "#{width}x#{height}" if columns != width || rows != height
       end
-      img = yield(img) if block_given?
-      img
+      image = yield(image) if block_given?
+      image
     end
   end
 
@@ -61,17 +61,11 @@ class Image
 
   def manipulate!
     image = ::MiniMagick::Image.open(path)
-    begin
-      image = yield(image)
-      image.write(path)
-      image.run_command("identify", path)
-    ensure
-      image.destroy!
-    end
-  rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
-    default = I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :locale => :en)
-    message = I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :default => default)
-    raise CarrierWave::ProcessingError, message
+    image = yield(image)
+    image.write(path)
+    image.run_command("identify", path)
+  ensure
+    image.destroy!
   end
 
   def sanitize(name)