Thumbnail Options
The options for a thumbnail are held in a ThumbnailOptions dictionary,
which applies the default options and is used to build the thumbnail’s file
name.
- class easy_thumbnails.options.ThumbnailOptions(*args, **kwargs)
A dictionary of thumbnail options (e.g.
{'size': (100, 100), 'crop': True}), as passed to the source generators, the processors andengine.save_pil_image.Thumbnailer.get_optionsand the engine wrap plain dictionaries in it. See Usage and Image Processors for the available options.On creation, it:
adds the entries of
THUMBNAIL_DEFAULT_OPTIONSthat aren’t given,sets
subsamplingto 4:2:0 (JPEG_CSS_420) if it isn’t given,normalizes
format: lowercased, without a leading., andjpegbecomesjpg. It must be one ofOUTPUT_FORMATS(jpg,webp,avif), otherwise aValueErroris raised.
It doesn’t add a
quality;Thumbnailer.resolve_qualityadds the default quality of the output format fromTHUMBNAIL_IMAGE_SAVE_OPTIONS. It doesn’t parse asizestring either (the{% thumbnail %}tag does).prepared_options()turns the options into the parts of the thumbnail file name.- prepared_options()
Return the options as a list of strings used to name the thumbnail.
The first item is the size (
'100x50'). The second item is the quality ('q76'). It gets ansspart with the subsampling, if it is not the default ('q76ss0'). The default is 4:2:0, which Pillow indicates withsubsampling=2. It is left out if there is neither a quality nor a non-default subsampling (e.g. for formats without a configured default quality).The remaining options follow in key order. A
Truevalue is added askey. Any other value is added askey-value. Sequences are comma-joined.Falsy values and uppercase keys are skipped, they don’t affect the filename. The
formatkey is skipped too: it already determines the file extension, so it is not repeated in the name.This is only used for naming:
Thumbnailer.get_thumbnail_namejoins the list with_for the%(opts)sbasedir/subdir templates and passes it to the namer asprepared_options.Image generation does not use it; the processors, source generators and
engine.save_pil_imageread the full options dict.The size must stay the first item, since the built-in
source_hashednamer relies on it!