Skip to content

Instantly share code, notes, and snippets.

@lepture
Created January 9, 2014 16:49
Show Gist options
  • Save lepture/8337551 to your computer and use it in GitHub Desktop.
Save lepture/8337551 to your computer and use it in GitHub Desktop.
# 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
@ikbear
Copy link

ikbear commented Jan 9, 2014

宽度大于某个固定值的时候才缩放或者裁剪,高度等比缩放。这个很好理解。

关键是 resize(width, height) 的行为是怎么样的?它是仅仅缩放吗?还是会裁剪?缩放的时候又是先满足宽度呢,还是高度?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment