aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/views.py
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-08-28 21:12:20 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-08-28 21:12:20 +0200
commit5aa00975ffc018c9f6680852a599bd438003f77c (patch)
tree9c9b71d75582a3f8212a3d6e2a6d5b17a3f4192a /accounts/views.py
parentupload multiple files (diff)
downloadscout-subs-5aa00975ffc018c9f6680852a599bd438003f77c.tar.gz
scout-subs-5aa00975ffc018c9f6680852a599bd438003f77c.zip
vertical concatanate images, resize images
Diffstat (limited to 'accounts/views.py')
-rw-r--r--accounts/views.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/accounts/views.py b/accounts/views.py
index 9bdfacf..696391d 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -94,7 +94,7 @@ def personal(request):
filename = filename + ".jpg"
# encode in JPEG
- im = Image.open(medic.vac_certificate.file)
+ im = Image.open(medic.health_care_certificate.file)
im_io = BytesIO()
im.save(im_io, 'JPEG', quality=90)
im_io.seek(0)
@@ -157,12 +157,15 @@ def personal(request):
im = Image.open(files.pop(0))
for f in files:
i = Image.open(f)
- dst = Image.new('RGB', (im.width + i.width, max(im.height, i.height)), (255, 255, 255))
+ dst = Image.new('RGB', (max(im.width, i.width), im.height + i.height), (255, 255, 255))
dst.paste(im, (0, 0))
- dst.paste(i, (im.width, 0))
+ dst.paste(i, (0, im.height))
im = dst
im_io = BytesIO()
+ # resize image if larger than max value
+ if im.height > 16383:
+ im = im.resize((round(im.width/im.height*16383), 16383))
# compress image in WEBP
im.save(im_io, 'WEBP', quality=50, method=4)
medic.vac_certificate.save(
@@ -171,6 +174,9 @@ def personal(request):
except UnidentifiedImageError:
error = True
error_text = "Il file non è un immagine valida"
+ except IOError:
+ error = True
+ error_text = "Il file è un immagine troppo grande"
if "health_care_certificate" in request.FILES:
files = request.FILES.getlist('health_care_certificate')
@@ -183,12 +189,15 @@ def personal(request):
im = Image.open(files.pop(0))
for f in files:
i = Image.open(f)
- dst = Image.new('RGB', (im.width + i.width, max(im.height, i.height)), (255, 255, 255))
+ dst = Image.new('RGB', (max(im.width, i.width), im.height + i.height), (255, 255, 255))
dst.paste(im, (0, 0))
- dst.paste(i, (im.width, 0))
+ dst.paste(i, (0, im.height))
im = dst
im_io = BytesIO()
+ # resize image if larger than max value
+ if im.height > 16383:
+ im = im.resize((round(im.width/im.height*16383), 16383))
# compress image in WEBP
im.save(im_io, 'WEBP', quality=50, method=4)
medic.health_care_certificate.save(
@@ -197,6 +206,9 @@ def personal(request):
except UnidentifiedImageError:
error = True
error_text = "Il file non è un immagine valida"
+ except IOError:
+ error = True
+ error_text = "Il file è un immagine troppo grande"
# user requested file delete
if request.POST["delete_vac"] == 'vac':