Package: easy-thumbnails
A powerful, yet easy to implement thumbnailing application for Django 2.2+Below is a quick summary of usage. For more comprehensive information, view thefull documentationonline or the peruse the project’sdocsdirectory.Breaking NewsVersion 2.8.0 adds support for thumbnailing SVG images when installed with the[svg]extra.Of course it doesn’t make sense to thumbnail SVG images, because being in vector format they can
scale to any size without quality of loss. However, users of easy-thumbnails may want to upload and
use SVG images just as if they would be PNG, GIF or JPEG. They don’t necessarily care about the
format and definitely don’t want to convert them to a pixel based format. What they want is to reuse
their templates with the templatetag thumbnail and scale and crop the images to whatever their<img src=”…” width=”…” height=”…”>has been prepared for.This is done by adding an emulation layer named VIL, which aims to be compatible with thePILlibrary. All thumbnailing operations, such as scaling and
cropping behave like pixel based images. The final filesize of such thumbnailed SVG images doesn’t
of course change, but their width/height and bounding box may be adjusted to reflect the desired
size of the thumbnailed image.NoteThis feature is new and experimental, hence feedback about its proper functioning in
third parts applications is highly appreciated.InstallationRunpip installeasy-thumbnails.Addeasy_thumbnailsto yourINSTALLED_APPSsetting:INSTALLED_APPS=(...'easy_thumbnails',)Runmanage.py migrate easy_thumbnails.Example usageThumbnail options can be predefined insettings.THUMBNAIL_ALIASESor just
specified in the template or Python code when run.Using a predefined aliasGiven the following setting:THUMBNAIL_ALIASES={'':{'avatar':{'size':(50,50),'crop':True},},}Template:{%loadthumbnail%}<imgsrc="{{profile.photo|thumbnail_url:'avatar'}}"alt=""/>Python:fromeasy_thumbnails.filesimportget_thumbnailerthumb_url=get_thumbnailer(profile.photo)['avatar'].urlManually specifying size / optionsTemplate:{%loadthumbnail%}<imgsrc="{%thumbnailprofile.photo50x50crop%}"alt=""/>Python:fromeasy_thumbnails.filesimportget_thumbnaileroptions={'size':(100,100),'crop':True}thumb_url=get_thumbnailer(profile.photo).get_thumbnail(options).urlUsing in combination with other thumbnailersAlternatively, you load the templatetags by {% load easy_thumbnails_tags %}
instead of traditional {% load thumbnail %}. It’s especially useful in
projects that do make use of multiple thumbnailer libraries that use the
same name (thumbnail) for the templatetag module:{%loadeasy_thumbnails_tags%}<imgsrc="{%thumbnailprofile.photo50x50crop%}"alt=""/>FieldsYou can useThumbnailerImageField(orThumbnailerField) for easier
access to retrieve or generate thumbnail images.For example:fromeasy_thumbnails.fieldsimportThumbnailerImageFieldclassProfile(models.Model):user=models.OneToOneField('auth.User')photo=ThumbnailerImageField(upload_to='photos',blank=True)Accessing the field’s predefined alias in a template:{%loadthumbnail%}<imgsrc="{{profile.photo.avatar.url}}"alt=""/>Accessing the field’s predefined alias in Python code:thumb_url=profile.photo['avatar'].urlThumbnail optionscropBefore scaling the image down to fit within thesizebounds, it first cuts
the edges of the image to match the requested aspect ratio.Usecrop="smart"to try to keep the most interesting part of the image,Usecrop="0,10"to crop from the left edge and a 10% offset from the
top edge. Crop from a single edge by leaving dimension empty (e.g.crop=",0"). Offset from the right / bottom by using negative numbers
(e.g., crop=”-0,-10”).Often used with theupscaleoption, which will allow enlarging of the image
during scaling.quality=XXChanges the quality of the output JPEG thumbnail. Defaults to85.In Python code, this is given as a separate option to theget_thumbnailmethod rather than just alter the otherOther optionsValid thumbnail options are determined by the “thumbnail processors” installed.See thereference documentationfor a complete list of options provided by
the default thumbnail processors.Changes2.8.5 (2023-01-09)Fix regression introduced in version 2.8.4. Argumentqualityis not removed for images
of type.webp.2.8.4 (2022-12-19)Fix problem when thumbnailing images of type TIFF. PIL’sTiffImagePlugindoesn’t
like argumentquality.Replace deprecated Pillow constants against newer counterparts. Checkhttps://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#deprecationsfor details.2.8.3 (2022-08-02)Fix regression in library detection introduced  in version 2.8.2.2.8.2 (2022-07-31)Installation of easy-thumbnails now optionally depends on the reportlab library.2.8.1 (2022-01-20)Add support for Django 4.NewTHUMBNAIL_IMAGE_SAVE_OPTIONSsetting.Fix #587: Uploading SVG Images to S3 storage.2.8.0 (2021-11-03)Add support for thumbnailing SVG images. This is done by adding an emulation layer named VIL,
which aims to be compatible with PIL. All thumbnailing operations, such as scaling and cropping
behave like pixel images.Remove configuration directivesTHUMBNAIL_HIGH_RESOLUTIONandTHUMBNAIL_HIGHRES_INFIXfrom easy-thumbnails setting directives.2.7.2 (2021-10-17)Add support for Django 3.2 and Python-3.10.Fix #563: Do not close image after loading content.In management commandthumbnail_cleanup, replaceprint-statements
againststdout.write.Use Python format strings whereever possible.2.7.1 (2020-11-23)Add support for Django 3.12.7.0 (2019-12-15)Add support for Django 3.0Drop support for Python 2Drop support for Django < 1.11Drop support for Django 2.0, 2.12.6.0 (2019-02-03)Added testing for Django 2.2 (no code changes required).2.5.0 (2017-10-31)Support Django versions up to 1.11. Version 2.0 is in beta.Fix: Pickle/unpickle machine. The ThumbnailerField fields no longer
generated thumbnails.Removed all references to South migrations.2.4.2 (2017-09-14)Supported Django versions are now 1.8 or 1.10+, Python 2.7 minimum.Fix IOError saving JPEG files with transparency on Pillow 4.2+.Fix #450, #473: fixed int/string is not a callable in management command.Fix #456: Delete method of ThumbnailerFieldFile is called twice.2.4.1 (2017-04-05)New minimum requirement of Django 1.4 or 1.7+.Fix EXIF orientation to use transpose.Upgrades to avoid deprecation warnings.Fix app settings not working in Django 1.11.Fix a bad conditional check causing incorrect behaviour in autocropping
transparent images.Django 1.8+ compatibility forthumbnail_cleanupcommand.Addeasy_thumbnails_tagstemplate tag mirror to allow multiple
thumbnailer libraries to coexist happily.Limit pillow to its final compatible version when on Python 2.6Fix tests.2.3 (2015-12-11)NewAliasnamer.Avoid a potential concurrency issue with creating the cache.Fix incorrect use of select_related for source thumbnail model.Removed some vestigal processor arguments.AllowHIGH_RESOLUTIONargument on thumbnail template tag.Add logic to correctly handle thumbnail images on deferred models (e.g. when
using.only()).Add adata_urifilter to allow rendering of an image inline as a data
uri.2.2.1 (2014-12-30)Fixed: Optionzoomcan also be used by itself, without combining it withcrop.2.2 (2014-10-04)Fix migrations for Django 1.7 final.Fix contain bad image EXIFs being able to still raise an exception.2.1 (2014-08-13)Fix Python 3.4 installation issue.Avoid an OverflowError due to invalid EXIF data.Fix bug causing JPEG images to be saved without optimization :(JPEG files can now be saved with progressive encoding. By default, any image
with a dimension larger than 100px will be saved progressively. Configured
with theTHUMBNAILER_PROGRESSIVEsetting.2.0.1 (2014-04-26)Fix packaging issue with old south migrations.2.0 (2014-04-25)Use Django 1.7 migrations. Thanks Trey Hunner.Note: if using South, read the installation docs for required settings
changes.Make ThumbnailerImageField.resize_source reflect change in extension.Addtargetoption to the scale_and_crop processor, allowing for image
focal points when cropping (or zooming) an image.Add a THUMBNAIL_NAMER option which takes a function used to customize
the thumbnail filename.Newsubsamplingoption to reduce color subsampling of JPEG images,
providing sharper color borders for a small increase in file size.Reimplementation of thethumbnail_cleanupcommand. Thanks Jørgen
AbrahamsenMore efficient thumbnail default storage. Thanks Sandip Agarwal.1.5 (2014-03-05)Better support for multiple source generators.Update method used to check for modification dates of source and thumbnail
images. Thanks Ben Roberts.Better thumbnail_high_resolution handling, including the ability to switch on
and off explicitly with aHIGH_RESOLUTIONthumbnail option.Added configuration option to specify the infix used for high resolution
image handling.Optional postprocessor for image optimization. Thanks Jacob Rief!More remote storages optimizationThumbnail dimensions can now optionally be cached. Thanks David Novakovic.Newzoomoption to generate a thumbnail of a source image with a
percentage clipped off each side.Newbackgroundsource processor that can add a border color to ensure
scaled images fit within the exact dimensions given.1.4 (2013-09-23)Considerable speed up for remote storages by reducing queries.
Brent O’Connor spent a lot of time debugging this, so thank you epicserve!Allow the{% thumbnail %}tag to also accept aliases. Thanks Simon Meers!Makereplace_alphaactually work correctly.Fixes exception being raised when image exists in cache but is doesn’t
actually exist in the storage.Fixes Python 2.5 compatibility.1.3 (2013-06-17)Some more Django 1.5 fixes.Fix an issue withThumbnail.urlnot working correctly.Add the ability to generate retina quality thumbnails in addition to the
standard ones (off by default).1.2 (2013-01-23)Django 1.5 compatibility.Fixed a problem with theImageClearableFileInputwidget.1.1 (2012-08-29)Added a way to avoid generating thumbnails if they don’t exist already (with
a signal to deal with them elsewhere).Added athumbnailer_passivefilter to allow templates to use the
non-generating thumbnails functionality when dealing with aliases.1.0.3 (2012-05-30)Changed the exception to catch from 1.0.2 to IOError.1.0.2 (2012-05-29)Catch an OSError exception when trying to get the EXIF data of a touchy
image.1.0.1 (2012-05-23)Fix a Django 1.2 backwards incompatibility ineasy_thumbnails.confIntroduced athumbnail_createdsignal.1.0 (2012-05-07)Introduction of aliased thumbnails.Start of sane versioning numbers.