From 08ab4b2924dd4c8a0309e7226320a9546e5ffa21 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 21 Jan 2022 03:17:21 +0000 Subject: [PATCH] Stop detection of MP0 images --- apiserver/apiserver/api/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index 39ad5c9..c0f0a1c 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -10,7 +10,8 @@ from rest_framework.exceptions import ValidationError from rest_framework.views import exception_handler from dateutil import relativedelta from uuid import uuid4 -from PIL import Image, ImageDraw, ImageFont, ImageOps +from PIL import Image, ImageDraw, ImageFont, ImageOps, JpegImagePlugin +#JpegImagePlugin._getmp = lambda x: None from bleach.sanitizer import Cleaner from PyPDF2 import PdfFileWriter, PdfFileReader from reportlab.pdfgen import canvas @@ -179,14 +180,16 @@ def process_image_upload(upload, crop): try: pic = Image.open(upload) except OSError: - raise serializers.ValidationError('Invalid image file.') + raise serializers.ValidationError(dict(photo='Invalid image file.')) + + logging.info('Detected format: %s', pic.format) if pic.format == 'PNG': ext = '.png' elif pic.format == 'JPEG': ext = '.jpg' else: - raise serializers.ValidationError('Image must be a jpg or png.') + raise serializers.ValidationError(dict(photo='Image must be a jpg or png.')) pic = ImageOps.exif_transpose(pic)