New IS_IMAGE validator
[edit]New IS_IMAGE validator can be used to check if file uploaded through file input was saved in one of selected image formats and has dimensions (width and height) within given boundaries. Everything is done in pure Python (no PIL or other libraries required).
Note that this does not check for image size - use IS_LENGTH for that.
Supported file formats: BMP, GIF, JPEG, PNG.
INPUT(_type='file', _name='name', requires=IS_IMAGE(extensions=('bmp', 'gif',
'jpeg', 'png'),
maxsize=(10000, 10000),
minsize=(0, 0),
error_message='invalid
image!'))
- extensions: iterable containing allowed lowercase image file extensions ('jpg' extension of uploaded file counts as 'jpeg')
- maxsize: iterable containing maximum width and height of the image
- minsize: iterable containing minimum width and height of the image
Use (-1, -1) as minsize to pass image size check.
Examples:
Check if uploaded file is in any of supported image formats:
INPUT(_type='file', _name='name', requires=IS_IMAGE())
Check if uploaded file is either JPEG or PNG:
INPUT(_type='file', _name='name', requires=IS_IMAGE(extensions=('jpeg', 'png')))
Check if uploade file is PNG with maximum size of 200x200 pixels:
INPUT(_type='file', _name='name', requires=IS_IMAGE(extensions=('png'),
maxsize=(200, 200)))