• loading...

This validator checks if a file uploaded through the file input was saved in one of the selected image formats and has dimensions (width and height) within given limits.  It does not check for maximum file size (use IS_LENGTH for that). It returns a validation failure if no data was uploaded. It supports the file formats BMP, GIF, JPEG, PNG, and it does not require the Python Imaging Library.

Note: on displaying an edit form for a table including requires = IS_IMAGE(), a delete checkbox will NOT appear because to delete the file would cause the validation to fail. To display the delete checkbox use this validation: 
requires = IS_EMPTY_OR(IS_IMAGE())

# Check if uploaded file is in any of supported image formats

requires = IS_IMAGE()

Attributes / Arguments

Iterable containing allowed image file extensions in lowercase

# Check if uploaded file is either JPEG or PNG:
requires = IS_IMAGE(extensions=('jpeg', 'png'))

Iterable containing maximum width and height of the image

requires = IS_IMAGE(maxsize=(200, 200))

Iterable containing minimum width and height of the image

requires = IS_IMAGE(minsize=(200, 200))


Sources / Reference

" Web2py Book"



Powered by

Hosted on
(affiliated link)