Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added avif support #772

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sorl-thumbnail::
Depending of the chosen image backend, you may also use one of::

pip install sorl-thumbnail[pil]
pip install sorl-thumbnail[pil, avif]
pip install sorl-thumbnail[wand]
pip install sorl-thumbnail[pgmagick]

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ The generated thumbnails filename prefix.

- Default: ``'JPEG'``

Default image format, supported formats are: ``'JPEG'``, ``'PNG'``. This also implicitly
Default image format, supported formats are: ``'JPEG'``, ``'PNG'``, ``'GIF'``, ``'WEBP'``, ``'AVIF'``. This also implicitly
sets the filename extension. This can be overridden by individual options.

``THUMBNAIL_PRESERVE_FORMAT``
Expand Down Expand Up @@ -358,7 +358,7 @@ missing input source.
This is the generated thumbnail whensource of the presented thumbnail. Width and
Height is passed to the string for formatting. Other options are for example:

- ``https://via.placeholder.com/%(width)sx%(height)s
- ``https://via.placeholder.com/%(width)sx%(height)s``
- ``http://placekitten.com/%(width)s/%(height)s``


Expand Down
4 changes: 4 additions & 0 deletions docs/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ want to see the following::

--- JPEG support available
--- ZLIB (PNG/ZIP) support available

to activate avif support install the plugin::

pip install sorl-thumbnail[avif, pil]

pgmagick installation
---------------------
Expand Down
17 changes: 17 additions & 0 deletions docs/template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ these things out::
else:
self.storage = default_storage

Format
------

sorl-thumbnail supports these formats:

#. jpg, jpeg
#. png
#. gif
#. webp
#. avif (requires pillow and pillow-avif-plugin)

to use different format for your images set this variable in your settings.

.. code-block:: python

THUMBNAIL_FORMAT = 'JPEG'

Geometry
--------

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Repository = "https://github.com/jazzband/sorl-thumbnail"
pgmagick = ["pgmagick"]
pil = ["pillow"]
wand = ["wand"]
avif = ["pillow-avif-plugin"]

[tool.coverage.run]
source = ["sorl"]
Expand Down
3 changes: 3 additions & 0 deletions sorl/thumbnail/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'PNG': 'png',
'GIF': 'gif',
'WEBP': 'webp',
'AVIF': 'avif',
}


Expand Down Expand Up @@ -57,6 +58,8 @@ def _get_format(self, source):
return 'GIF'
elif file_extension == '.webp':
return 'WEBP'
elif file_extension == '.avif':
return 'AVIF'
else:
from django.conf import settings

Expand Down
4 changes: 4 additions & 0 deletions sorl/thumbnail/engines/pil_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import ImageDraw
import ImageFile
import ImageMode
try:
import pillow_avif # noqa: F401
except ImportError:
pass

if hasattr(Image, 'Resampling'):
ANTIALIAS = Image.Resampling.LANCZOS
Expand Down
1 change: 1 addition & 0 deletions tests/thumbnail_tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_with_various_formats(self):
self.assertEqual(self.backend._get_format(FakeFile('foo.jpeg')), 'JPEG')
self.assertEqual(self.backend._get_format(FakeFile('foo.png')), 'PNG')
self.assertEqual(self.backend._get_format(FakeFile('foo.gif')), 'GIF')
self.assertEqual(self.backend._get_format(FakeFile('foo.avif')), 'AVIF')

def test_double_extension(self):
self.assertEqual(self.backend._get_format(FakeFile('foo.ext.jpg')), 'JPEG')
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ envlist =
deps =
coverage[toml]
pillow
pillow-avif-plugin
redis: redis
dynamodb: boto
pgmagick: pgmagick
Expand Down