summaryrefslogtreecommitdiff
path: root/app/photos
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2016-03-27 20:38:22 -0400
committerluxagraf <sng@luxagraf.net>2016-03-27 20:38:22 -0400
commitc626861546bc3e33b068d929174a7d478c4f2bab (patch)
tree2dee144be55882b59f7a9a1445d6aaadfaaa5c1a /app/photos
parent64f5a3f949c94248e90d1583cb1cd558cda1acf7 (diff)
fixed photo resizer to work with gallery uploads
Diffstat (limited to 'app/photos')
-rw-r--r--app/photos/forms.py29
-rw-r--r--app/photos/models.py19
2 files changed, 26 insertions, 22 deletions
diff --git a/app/photos/forms.py b/app/photos/forms.py
index 03c6f09..16ba890 100644
--- a/app/photos/forms.py
+++ b/app/photos/forms.py
@@ -148,28 +148,19 @@ class UploadZipForm(forms.Form):
)
contentfile = ContentFile(data)
image.image.save(filename, contentfile)
- image.save()
- gallery.images.add(image)
- readexif(image)
- count += 1
img = Image.open(image.image.path)
- base_path = "%s/galleries/" % settings.IMAGES_ROOT
if img.size[0] > img.size[1]:
- resize_image(img, 2280, None, 65, base_path+'large/', image.get_image_name())
- image.sizes.add(LuxImageSize.objects.get(size=2280))
- resize_image(img, 1140, None, 72, base_path+'medium/', image.get_image_name())
- image.sizes.add(LuxImageSize.objects.get(size=1140))
- resize_image(img, 720, None, 68, base_path+'small/', image.get_image_name())
- image.sizes.add(LuxImageSize.objects.get(size=720))
+ image.sizes.add(LuxImageSize.objects.get(width=2280))
+ image.sizes.add(LuxImageSize.objects.get(width=1140))
+ image.sizes.add(LuxImageSize.objects.get(width=720))
if img.size[1] > img.size[0]:
- resize_image(img, None, 1600, 65, base_path+'large/', image.get_image_name())
- image.sizes.add(LuxImageSize.objects.get(size=1600))
- resize_image(img, None, 800, 72, base_path+'medium/', image.get_image_name())
- image.sizes.add(LuxImageSize.objects.get(size=800))
- resize_image(img, None, 460, 60, base_path+'small/', image.get_image_name())
- image.sizes.add(LuxImageSize.objects.get(size=460))
-
- resize_image(img, 160, None, 68, base_path+'thumb/', image.get_image_name())
+ image.sizes.add(LuxImageSize.objects.get(width=1600))
+ image.sizes.add(LuxImageSize.objects.get(width=800))
+ image.sizes.add(LuxImageSize.objects.get(width=460))
+ image.save()
+ gallery.images.add(image)
+ base_path = "%s/galleries/" % settings.IMAGES_ROOT
+
zipper.close()
if request:
diff --git a/app/photos/models.py b/app/photos/models.py
index 6907a25..3ae58e4 100644
--- a/app/photos/models.py
+++ b/app/photos/models.py
@@ -10,6 +10,8 @@ from django.conf import settings
from taggit.managers import TaggableManager
from locations.models import Location, Region
+from resizeimage.imageexceptions import ImageSizeError
+
from .utils import resize_image
from .readexif import readexif
from django.db.models.signals import post_save
@@ -121,13 +123,24 @@ def post_save_events(sender, update_fields, created, instance, **kwargs):
@receiver(m2m_changed, sender=LuxImage.sizes.through)
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, 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()))
+ if img.size[0] > img.size[1]:
+ try:
+ resize_image(img, size.width, None, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext()))
+ except ImageSizeError:
+ m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through)
+ instance.sizes.remove(size)
+ m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through)
+ if img.size[1] > img.size[0]:
+ try:
+ resize_image(img, None, size.width, size.quality, base_path, "%s_%s.%s" % (instance.get_image_name(), size.width, instance.get_image_ext()))
+ except ImageSizeError:
+ m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through)
+ instance.sizes.remove(size)
+ m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through)
class LuxGallery(models.Model):