Created
January 9, 2014 16:49
-
-
Save lepture/8337551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from wand.image import Image | |
def resize(blob, min=300, max=1200): | |
image = Image(blob=blob) | |
width = image.width | |
height = image.height | |
if width < min: | |
raise ValueError('Image is too small for displaying.') | |
if width > max: | |
height = int(round(float(max) / width * height)) | |
width = max | |
image.resize(width, height) | |
return image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
宽度大于某个固定值的时候才缩放或者裁剪,高度等比缩放。这个很好理解。
关键是 resize(width, height) 的行为是怎么样的?它是仅仅缩放吗?还是会裁剪?缩放的时候又是先满足宽度呢,还是高度?