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:
parent
222df2ba2a
commit
946b0847d8
2 changed files with 6 additions and 2 deletions
|
@ -133,7 +133,7 @@ class MediaAssetFile(object):
|
||||||
mediaFile.crop(*dims)
|
mediaFile.crop(*dims)
|
||||||
elif command == "size":
|
elif command == "size":
|
||||||
size = [int(i) for i in args.split(",")]
|
size = [int(i) for i in args.split(",")]
|
||||||
if size and len(size) == 2:
|
if size:
|
||||||
mediaFile.resize(*size)
|
mediaFile.resize(*size)
|
||||||
outputFormat = self.getContentType(variant)
|
outputFormat = self.getContentType(variant)
|
||||||
mediaFile.save(path, outputFormat)
|
mediaFile.save(path, outputFormat)
|
||||||
|
|
|
@ -93,9 +93,13 @@ class PILTransform(object):
|
||||||
box = (left, upper, right, lower)
|
box = (left, upper, right, lower)
|
||||||
self.im = self.im.crop(box)
|
self.im = self.im.crop(box)
|
||||||
|
|
||||||
def resize(self, width, height):
|
def resize(self, width, height=None):
|
||||||
if self.im is None:
|
if self.im is None:
|
||||||
return
|
return
|
||||||
|
if not height:
|
||||||
|
ow, oh = self.im.size
|
||||||
|
ratio = float(ow) / float(oh)
|
||||||
|
height = int(round(float(width) / ratio))
|
||||||
dims = (width, height)
|
dims = (width, height)
|
||||||
self.im.thumbnail(dims, Image.ANTIALIAS)
|
self.im.thumbnail(dims, Image.ANTIALIAS)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue