mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
check if image is not corrupted during upload (#218)
This commit is contained in:
parent
dfb2cb67e7
commit
43e052ebd5
1 changed files with 7 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ from django.forms import widgets
|
||||||
from django.template.defaultfilters import filesizeformat
|
from django.template.defaultfilters import filesizeformat
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from PIL import Image, ImageOps
|
||||||
|
|
||||||
from avatar.conf import settings
|
from avatar.conf import settings
|
||||||
from avatar.models import Avatar
|
from avatar.models import Avatar
|
||||||
|
|
@ -82,6 +83,12 @@ class UploadAvatarForm(forms.Form):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
image = Image.open(data)
|
||||||
|
ImageOps.exif_transpose(image)
|
||||||
|
except TypeError:
|
||||||
|
raise forms.ValidationError(_("Corrupted image"))
|
||||||
|
|
||||||
count = Avatar.objects.filter(user=self.user).count()
|
count = Avatar.objects.filter(user=self.user).count()
|
||||||
if 1 < settings.AVATAR_MAX_AVATARS_PER_USER <= count:
|
if 1 < settings.AVATAR_MAX_AVATARS_PER_USER <= count:
|
||||||
error = _(
|
error = _(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue