webhelpers.media

Multimedia helpers for images, etc.

webhelpers.media.choose_height(new_width, width, height)

Return the height corresponding to new_width that’s proportional to the original size (width x height).

webhelpers.media.get_dimensions_pil(path, default=(None, None))

Get an image’s size using the Python Imaging Library (PIL).

path is the path of the image file.

default is returned if the size could not be ascertained. This usually means the file does not exist or is not in a format recognized by PIL.

The normal return value is a tuple: (width, height).

Depends on the Python Imaging Library. If your application is not otherwise using PIL, see the get_dimensions() function, which does not have external dependencies.

webhelpers.media.get_dimensions(path, default=(None, None))

Get an image’s size using only the Python standard library.

path is the path of the image file.

default is returned if the size could not be ascertained. This usually means the file does not exist or is not in a recognized format. PIL. Only JPG, PNG, GIF, and BMP are supported at this time.

The normal return value is a tuple: (width, height).

The algorithms are based on a PyCode recipe by Perenzo/Welch/Ray.

This helper recognizes fewer image formats and is potentially less accurate than get_dimensions_pil().

Running this module as a script tests this helper. It will print the size of each image file specified on the command line.

Previous topic

webhelpers.html.tools

Next topic

webhelpers.mimehelper