just checking that this didn't slip through the cracks (bug shoes-12
is still open)

martin


---------- Forwarded message ----------
From: Martin DeMello <[EMAIL PROTECTED]>
Date: Fri, Jul 11, 2008 at 4:07 PM
Subject: patch: scale image proportionately if only width or height are given
To: [email protected]


fix for bug shoes-12

martin
diff --git a/lib/shoes/image.rb b/lib/shoes/image.rb
index 80fe69d..1540e4d 100644
--- a/lib/shoes/image.rb
+++ b/lib/shoes/image.rb
@@ -13,6 +13,15 @@ class Shoes
       path, opts = args
       opts ||= {}
 
+      # scaling 
+      w, h = imagesize(path)
+      ow, oh = opts[:width], opts[:height]
+      if ow && !oh
+        opts[:height] = (ow.is_a? Float) ? ow : (ow * h/w.to_f).to_i
+      elsif oh && !ow
+        opts[:width]  = (oh.is_a? Float) ? oh : (oh * w/h.to_f).to_i
+      end
+
       path = path.to_str
       uri = Shoes.uri(path) unless uri.is_a? URI
       realpath = path

Reply via email to