Package web2py :: Package gluon :: Module validators :: Class IS_IMAGE

[hide private]
[frames] | no frames]

# Class IS_IMAGE

source code

    object --+
             |
     Validator --+
                 |
                IS_IMAGE

Checks if file uploaded through file input was saved in one of selected image formats and has dimensions (width and height) within given boundaries.

Does *not* check for maximum file size (use IS_LENGTH for that). Returns validation failure if no data was uploaded.

Supported file formats: BMP, GIF, JPEG, PNG.

Code parts taken from http://mail.python.org/pipermail/python-list/2007-June/617126.html

Arguments:

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 uploaded file is PNG with maximum size of 200x200 pixels:
       INPUT(_type='file', _name='name',
           requires=IS_IMAGE(extensions=('png'), maxsize=(200, 200)))

Instance Methods | [hide private]

__init__(self, extensions=`(``'``bmp``'``,` `'``gif``'``,` `'``jpeg``'``,` `'``png``'``)`, maxsize=`(`10000`,` 10000`)`, minsize=`(`0`,` 0`)`, error_message=`'``invalid image``'`) x.__init__(...) initializes x; see x.__class__.__doc__ for signature | source code

__call__(self, value) | source code

__bmp(self, stream) | source code

__gif(self, stream) | source code

__jpeg(self, stream) | source code

__png(self, stream) | source code

Inherited from `Validator`: `formatter` Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

Properties | [hide private]

Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, extensions=`(``'``bmp``'``,` `'``gif``'``,` `'``jpeg``'``,` `'``png``'``)`, maxsize=`(`10000`,` 10000`)`, minsize=`(`0`,` 0`)`, error_message=`'``invalid image``'`)
(Constructor)

source code

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
  (inherited documentation)