Commit 02e86a17 authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

Merge branch 'feature/photo-resize-on-upload' into 'master'

Photo resize on upload

Dit is wel een goede oplossing, aldus @twiggers. Heb een setting gemaakt van de foto grootte, dus die kunnen we altijd nog aanpassen.

Closes #78

See merge request !81
parents 5c03c9b8 f7f9a217
......@@ -3,6 +3,8 @@ from django.conf import settings
from django.utils.functional import cached_property
from django.db import models
from PIL import Image
import hashlib
import os
import random
......@@ -24,9 +26,27 @@ class Photo(models.Model):
)
hidden = models.BooleanField(default=False)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.file:
self._orig_file = self.file.path
else:
self._orig_file = ""
def __str__(self):
return self.file.name
def save(self, *args, **kwargs):
super(Photo, self).save(*args, **kwargs)
if self._orig_file != self.file.path:
image_path = self.file.path
image = Image.open(image_path)
# Image.thumbnail does not upscale an image that is smaller
image.thumbnail(settings.PHOTO_UPLOAD_SIZE, Image.ANTIALIAS)
image.save(image_path, "JPEG")
self._orig_file = self.file.path
class Album(models.Model):
title = models.CharField(max_length=200)
......
......@@ -192,3 +192,6 @@ STATIC_PRECOMPILER_LIST_FILES = True
# Newsletter settings
NEWSLETTER_FROM_ADDRESS = 'nieuwsbrief@thalia.nu'
# Photos settings
PHOTO_UPLOAD_SIZE = 1920, 1080
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment