Author: tack
Date: Fri Jan 5 17:52:46 2007
New Revision: 2356
Modified:
trunk/imlib2/src/image.py
Log:
Make scale_preserve_aspect work when target aspect is different from
source aspect.
Modified: trunk/imlib2/src/image.py
==============================================================================
--- trunk/imlib2/src/image.py (original)
+++ trunk/imlib2/src/image.py Fri Jan 5 17:52:46 2007
@@ -269,14 +269,26 @@
"""
if 0 in (w, h):
raise ValueError, "Invalid scale size specified %s" % repr((w,h))
- aspect = float(self.width) / float(self.height)
- if aspect >= 1.0:
- img = self._image.scale(0, 0, self.width, self.height, w,
- int(h / aspect))
+
+ src_aspect = float(self.width) / self.height
+ dst_aspect = float(w) / h
+
+ if src_aspect >= 1.0:
+ if dst_aspect > src_aspect:
+ w = h * src_aspect
+ else:
+ h = w / src_aspect
else:
- img = self._image.scale(0, 0, self.width, self.height,
- int(w * aspect), h)
- return Image(img)
+ if dst_aspect > src_aspect:
+ w = h * src_aspect
+ else:
+ h = w / src_aspect
+
+ if (self.width, self.height) == (int(w), int(h)):
+ # No scale, just copy.
+ return self.copy()
+
+ return Image(self._image.scale(0, 0, self.width, self.height, int(w),
int(h)))
def thumbnail(self, (w, h)):
-------------------------------------------------------------------------
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