Thumbnail module

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

Bases: tuple

height[source]

Alias for field number 1

width[source]

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.

thumbnails[source]

The thumbnails property returns a list of available thumbnails.

get_source_size()[source]

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.

get_sizes()[source]

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

get_thumbnails()[source]

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.

get_name()[source]

Generate the thumbnail name for the current thumbnail configuration.

size[source]

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

viewport[source]

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.

exists(factor=1)[source]

Checks if the thumbnail already exists.

get_mimetype()[source]

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

get_storage_url(factor=1)[source]

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.

get_size(factor=1)[source]

Returns the actual generated thumbnail image size.

get_estimated_size()[source]

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.

generate(factor=1)[source]

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

get_gm_options(factor=1)[source]

Generates the option set dor Graphicsmagick to generate the thumbnail.

get_base64_content()[source]

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

get_base64_path(generate=True)[source]

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

generate_base64()[source]

Generate the base64 representation from the generated thumbnail image file.