allow resizing an image without specifying a height; this makes sure that the resulting image will have the width provided

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3991 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2010-09-11 07:30:54 +00:00
parent 222df2ba2a
commit 946b0847d8
2 changed files with 6 additions and 2 deletions

View file

@ -133,7 +133,7 @@ class MediaAssetFile(object):
mediaFile.crop(*dims)
elif command == "size":
size = [int(i) for i in args.split(",")]
if size and len(size) == 2:
if size:
mediaFile.resize(*size)
outputFormat = self.getContentType(variant)
mediaFile.save(path, outputFormat)

View file

@ -93,9 +93,13 @@ class PILTransform(object):
box = (left, upper, right, lower)
self.im = self.im.crop(box)
def resize(self, width, height):
def resize(self, width, height=None):
if self.im is None:
return
if not height:
ow, oh = self.im.size
ratio = float(ow) / float(oh)
height = int(round(float(width) / ratio))
dims = (width, height)
self.im.thumbnail(dims, Image.ANTIALIAS)