diff options
author | luxagraf <sng@luxagraf.net> | 2020-12-04 15:33:33 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2020-12-04 15:33:33 -0500 |
commit | cdaa099a3988b1487b6728215adbf1dc6c2c58fe (patch) | |
tree | 729568d0ac17919614669e9e91665d7889865450 /app/media | |
parent | 69a8baa1be1296e39a2596731209a2408770c123 (diff) |
added a function to generate images
Diffstat (limited to 'app/media')
-rw-r--r-- | app/media/models.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/media/models.py b/app/media/models.py index a5cacf5..b9437f1 100644 --- a/app/media/models.py +++ b/app/media/models.py @@ -397,3 +397,23 @@ def update_photo_sizes(sender, instance, **kwargs): print("file %s exists" % size) pass +def generate_image(luximage, size): + new_size = LuxImageSize.objects.get(slug=size) + if new_size.width: + img = Image.open(luximage.image.path) + try: + if new_size.width <= img.width: + resize_image(img, new_size.width, None, new_size.quality, luximage.get_image_path_by_size(size)) + else: + raise ValidationError({'items': ["Size is larger than source image"]}) + except ImageSizeError: + print("error creating size") + if new_size.height: + img = Image.open(luximage.image.path) + try: + if new_size.height <= img.height: + resize_image(img, None, new_size.height, new_size.quality, luximage.get_image_path_by_size(size)) + else: + pass + except ImageSizeError: + print("error creating size") |