Author: duncan
Date: Thu Jan  4 23:17:29 2007
New Revision: 8930

Modified:
   branches/rel-1/freevo/src/util/fileops.py

Log:
Added scale_rectangle_to_max for image scaling


Modified: branches/rel-1/freevo/src/util/fileops.py
==============================================================================
--- branches/rel-1/freevo/src/util/fileops.py   (original)
+++ branches/rel-1/freevo/src/util/fileops.py   Thu Jan  4 23:17:29 2007
@@ -541,6 +541,25 @@
     return create_thumbnail(filename, thumbnail)
 
 
+def scale_rectangle_to_max(size, max_size):
+    '''
+    returns a scaled rectangle size fitting the size to max_size
+    this can be used to scale images for viewing in a browser and
+    retaining the aspect ratio
+    '''
+    try:
+        scaled_width = max_size[0]
+        scaled_height = max_size[1]
+        # if actual image aspect ratio > scaled image aspect ratio then scale 
height
+        if float(size[0]) / size[1] > float(scaled_width) / scaled_height:
+            scaled_height = scaled_width * size[1] / size[0]
+        else: # else scale width
+            scaled_width = scaled_height * size[0] / size[1]
+    except ZeroDivisionError:
+        pass
+    return (scaled_width, scaled_height)
+
+
 def www_link_cachedir():
     '''returns the www link cache directory name
     if the directory does not exist it is created

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to