Skip to main content

optisorl

Copyright Peter Bengtsson, mail@peterbe.com, 2015-2016

Travis

License: BSD

About optisorl

sorl-thumbnail is a great Django library that takes your stored images and automatically convert them into desired sized thumbnails and store them with nice names in the MEDIA_ROOT. The problem is that the engines that do the resizing often doesn’t do an amazing job of optimizing them. Usually optimizing an image means carefully deleting things the human eye can’t notice anyway. This becomes incredibly relevant when the thumbnail you create is so small in resolution that the user really stands very little chance to notice.

This package, is a pluggable backend to sorl-thumbnail that attempts to do a good job of optimizing the generated thumbnail just right after it has been written to disk.

Installation

First, simply pip install optisorl.

Then add, in your Django settings:

THUMBNAIL_BACKEND = 'optisorl.backend.OptimizingThumbnailBackend'

Then review the sections below about being prepared for PNGs, GIFs and JPEGs.

Optimizing PNGs

optisorl uses a binary called pngquant which is a command line tool that do lossy compression of PNG images and supports alpha transparency. pngquant is BSD licensed. It’s easy to install on most systems. For example brew install pngquant or apt-get install pngquant.

What happens is that when optisorl notices that a thumbnail was created it (and stored in MEDIA_ROOT) it then takes that file and executes pngquant something like this:

pngquant -o /path/file.tmp.png --skip-if-larger -- /path/file.png

Note the --skip-if-larger which means that if the thumbnail is really really small already the resulting optimization might not be any better and it thus omits doing an optimization.

If you want to override the location of the executable pngquant you can set this setting for example:

# in settings.py or equivalent

PNGQUANT_LOCATION = '/opt/special/bin/pngquant2.0'

Optimizing GIFs

optisorl uses gifsicle with level 3 optimization. gifsicle is GPL licensed but use is not restricted by a license. To install it use brew install gifsicle or apt-get install gifsicle.

To override where the gifsicle executable is located you can set in your settings:

# in settings.py or equivalent

GIFSICLE_LOCATION = '/opt/special/bin/gifsicle'

If you want to disable all optimization of GIFs just set GIFSICLE_LOCATION (in your settings.py) to None or False.

Optimizing JPEGs

optisorl uses mozjpeg to optimize JPEGs. It’s a great fit because it almost never reduces the quality such that human eyes can notice it. Especially when the thumbnails are relatively small. The command that we use to execute mozjpeg looks like this:

mozjpeg -outfile DESTINATION -optimise SOURCE

You can override where the executable is by setting:

# in settings.py or equivalent

MOZJPEG_LOCATION = '/my/bin/mozjpeg'

For an example of what kind of results you can get with mozjpeg see this blog post: Examples of mozjpeg savings. Also see blog post mozjpeg installation and sample.

Limitations

Help is most welcome. At the moment…

  • Does not support S3 storage

  • Unable to NOT optimize images in run-time

  • Not possible to override certain pngquant parameters

  • Not possible to override certain gifsicle parameters

  • Not possible to override certain mozjpeg parameters

Release files for optisorl 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optisorl 0.2.1
File Size Uploaded
optisorl-0.2.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for optisorl 0.2.1
File Interpreter ABI Platform
optisorl-0.2.1-py2-none-any.whl Python 2 none any Details

Total release size: 11.3 kB

Release files / optisorl-0.2.1.tar.gz

Download URL optisorl-0.2.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4b18d8a270075aa0fe9588790162c03a80e822237e3346a2817d6e82236f1a49
BLAKE2b-256 checksum
How to use checksums
d2634bbbaa95e5ccf5f39ea723714aa2e1ae861e1ce8cf408a874d7aed5d7aeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / optisorl-0.2.1-py2-none-any.whl

Download URL optisorl-0.2.1-py2-none-any.whl
Size 6.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
808f22b6d4da608a255f40792e80cf8483f443425dbcb5f18ebe236295c19bbf
BLAKE2b-256 checksum
How to use checksums
e91917cf3bca1ba63dc633f5d146057f06096946a5c49f6ba4990f860d89010f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page