blob: 6cc64a398f301d87d91477bbf4a92691459e406a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import os
from resizeimage import resizeimage
def resize_image(img, width=None, height=None, quality=72, base_path="", filename=""):
if width and height:
newimg = resizeimage.resize_cover(img, [width, height])
if width and not height:
newimg = resizeimage.resize_width(img, width)
if height and not width:
newimg = resizeimage.resize_height(img, height)
if not os.path.isdir(base_path):
os.makedirs(base_path)
path = "%s%s" % (base_path, filename)
newimg.save(path, newimg.format, quality=quality)
|