summaryrefslogtreecommitdiff
path: root/app/media/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/media/models.py')
-rw-r--r--app/media/models.py20
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")