• 682 views
  • 0 comments
  • 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))


loading...

Sources / Reference

" Web2py Book"


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)