Custom validator to validate the maximum size of images
def maximum_size(width=None, height=None):
from PIL import Image
def validator(image):
img = Image.open(image)
fw, fh = img.size
if fw > width or fh > height:
raise ValidationError(
"Height or Width is larger than what is allowed")
return validator
class Photo(models.Model):
image = models.ImageField('Image', upload_to=image_upload_path, validators=[maximum_size(128,128)])
Custom validator to validate the maximum size of images
def maximum_size(width=None, height=None):
from PIL import Image
class Photo(models.Model):
image = models.ImageField('Image', upload_to=image_upload_path, validators=[maximum_size(128,128)])