From f2ebf135bbf0104d655160011571927ae459f728 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Mon, 21 Mar 2016 09:09:49 -0400 Subject: tweaked image size and quality settings --- app/photos/models.py | 2 +- app/photos/utils.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/photos/models.py b/app/photos/models.py index 46c659e..048dd65 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -125,7 +125,7 @@ def update_photo_sizes(sender, instance, **kwargs): print("hellow world") base_path = "%s/%s/" % (settings.IMAGES_ROOT, instance.pub_date.strftime("%Y")) img = Image.open(instance.image.path) - resize_image(img, 160, None, 65, base_path, "%s_tn.%s" % (instance.get_image_name(), instance.get_image_ext())) + resize_image(img, 160, None, 78, base_path, "%s_tn.%s" % (instance.get_image_name(), instance.get_image_ext())) for size in instance.sizes.all(): print(size.width) resize_image(img, size.width, None, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext())) diff --git a/app/photos/utils.py b/app/photos/utils.py index e880277..28047d4 100644 --- a/app/photos/utils.py +++ b/app/photos/utils.py @@ -1,5 +1,6 @@ import os import subprocess +from PIL import ImageFile # pip install python-resize-image from resizeimage import resizeimage @@ -15,5 +16,6 @@ def resize_image(img, width=None, height=None, quality=72, base_path="", filenam if not os.path.isdir(base_path): os.makedirs(base_path) path = "%s%s" % (base_path, filename) + ImageFile.MAXBLOCK = img.size[0] * img.size[1] * 4 newimg.save(path, newimg.format, quality=quality) subprocess.call(["jpegoptim", "%s" % path]) -- cgit v1.2.3-70-g09d2