diff options
Diffstat (limited to 'app/photos/utils.py')
-rw-r--r-- | app/photos/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/photos/utils.py b/app/photos/utils.py new file mode 100644 index 0000000..6cc64a3 --- /dev/null +++ b/app/photos/utils.py @@ -0,0 +1,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) |