Thumbnail module

class ultimatethumb.thumbnail.Size(width, height)[source]

Bases: tuple


Alias for field number 1


Alias for field number 0

class ultimatethumb.thumbnail.ThumbnailSet(source, sizes, options)[source]

Bases: object

A ThumbnailSet holds the source configuration and a number of thumbnails as requested.

__init__(source, sizes, options)[source]

Takes a valid source and a list of requested sizes together with additional options.


The thumbnails property returns a list of available thumbnails.


Returns the file size of the source.

If retina option is enabled, pretend that the source is half as large as it is. We do this to ensure that we have “retina” images which effectively are doubled in size. Doing this, we never have to upscale the image.


Parse the given sizes and return a list of size requests.


Returns a list of thumbnails based on the requested sizes. Some additional calculations are done to make sure we don’t return thumbnails larger than the source file is.

class ultimatethumb.thumbnail.Thumbnail(source, opts)[source]

Bases: object

This object represents a single thumbnail.

__init__(source, opts)[source]

Given a source and options, this method initializes the Thumbnail object. Some validation on the provided options are done.

classmethod from_name(name)[source]

Using a name, reconstruct a thumbnail object. The name is actually a cache key which is used by get_thumb_data to fetch the original thumbnail configuration.


Generate the thumbnail name for the current thumbnail configuration.


The size property returns the calculated, estimated thumbnail size without actually generating the thumbnail image.


Returns the valid viewport for this thumbnail, might be used in templates to configure the source sets properly.

property url[source]

The url property is responsible for returning the acutal thumbnail url.

property url_2x[source]

Returns the retina url for the thumbnail if retina is enabled.

property base64[source]

Returns the base64 representation of the thumbnail to use in a src attribute.

property requested_size[source]

Returns the requested thumbnail size.


Checks if the thumbnail already exists.


Returns the mime type of the thumbnail based on the thumbnail file name.


Returns the real url to use in the ultimatethumb view for returning the image.

get_storage_path(factor=1, generate=True)[source]

Returns the storage path in filesystem of the thumbnail file.


Returns the actual generated thumbnail image size.


Calculates the estimated thumbnail image dimensions based on the source size and the options provided.

get_storage_name(factor=1, suffix=None)[source]

Returns the name to use when storing the thumbnail to disk.


Genrate the thumbnail using Graphicsmagick and Pngquant (if enabled and source image is a png file.


Generates the option set dor Graphicsmagick to generate the thumbnail.


Reads the base64 version of the thumbnail from disk and returns content.


Calculates the path of the base64 image version. If path does not exist, base64 version is generated.


Generate the base64 representation from the generated thumbnail image file.