Browse Source

keep the original ratio for the resized image

pull/9/merge
Simon 14 years ago
parent
commit
6fe0f3d331
  1. 19
      sigal/image.py
  2. BIN
      tests/sample/dir1/test1.jpg

19
sigal/image.py

@ -48,12 +48,25 @@ class Image:
self.img.save(filename, quality=quality)
def resize(self, size):
"resize image"
"""Resize the image
- check if the image format is portrait or landscape and adjust `size`.
- compute the width and height ratio, and keep the min to resize the
image inside the `size` box without distorting it.
"""
if self.img.size[0] > self.img.size[1]:
self.img = self.img.resize(size, PILImage.ANTIALIAS)
newsize = size
else:
self.img = self.img.resize([size[1], size[0]], PILImage.ANTIALIAS)
newsize = (size[1], size[0])
wratio = newsize[0] / float(self.img.size[0])
hratio = newsize[1] / float(self.img.size[1])
ratio = min(wratio, hratio)
newsize = (int(ratio*self.img.size[0]), int(ratio*self.img.size[1]))
if ratio < 1:
self.img = self.img.resize(newsize, PILImage.ANTIALIAS)
def add_copyright(self, text):
"add copyright to image"

BIN
tests/sample/dir1/test1.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Loading…
Cancel
Save