From ce139ed46a2444cd2baa863548555ed89510530f Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 2 Aug 2022 17:00:31 +0200 Subject: [PATCH 1/4] Call PIL.Image.init to register all formats (fix #474) --- sigal/gallery.py | 5 ++++- tox.ini | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index d8a2351..926c4a0 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -235,6 +235,9 @@ class Image(Media): super().__init__(filename, path, settings) imgformat = settings.get('img_format') + # Register all formats + PILImage.init() + if imgformat and PILImage.EXTENSION[self.src_ext] != imgformat.upper(): # Find the extension that should match img_format extensions = {v: k for k, v in PILImage.EXTENSION.items()} @@ -492,7 +495,7 @@ class Album: def sort_key(s): sort_attr = albums_sort_attr if not isinstance(sort_attr,list): - sort_attr = [sort_attr] + sort_attr = [sort_attr] album = self.gallery.albums[join(root_path, s)] diff --git a/tox.ini b/tox.ini index 164d182..6c2e08b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,19 @@ [tox] -envlist = py{38,39,310}-pillow{71,80,-latest},pypy3,check +envlist = py{38,39,310}-pillow{80,90,-latest},pypy3,check skip_missing_interpreters = true isolated_build = true [gh-actions] python = - 3.8: py38-pillow71, check - 3.9: py39-pillow80 + 3.8: py38-pillow80, check + 3.9: py39-pillow90 3.10: py310-pillow-latest pypy3: pypy3 [testenv] deps = - pillow71: Pillow==7.1.0 - pillow80: Pillow==8.0.0 + pillow80: Pillow==8.0.1 + pillow90: Pillow==9.0.1 extras = all tests From 69ed93053e129cce24d85c6dfe29fd5825d63f4f Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 2 Aug 2022 17:08:02 +0200 Subject: [PATCH 2/4] Replace deprecated Image.ANTIALIAS --- sigal/image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sigal/image.py b/sigal/image.py index f0eb134..fafab13 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -162,9 +162,9 @@ def generate_thumbnail( original_format = img.format if fit: - img = ImageOps.fit(img, box, PILImage.ANTIALIAS, centering=thumb_fit_centering) + img = ImageOps.fit(img, box, PILImage.Resampling.LANCZOS, centering=thumb_fit_centering) else: - img.thumbnail(box, PILImage.ANTIALIAS) + img.thumbnail(box, PILImage.Resampling.LANCZOS) outformat = img.format or original_format or 'JPEG' logger.debug('Save thumnail image: %s (%s)', outname, outformat) From 3ce86e5763ec1e03ee08072fcde16252cbc0445a Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 2 Aug 2022 17:08:17 +0200 Subject: [PATCH 3/4] Bump Pillow requirement --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 39eb7c1..475d925 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,7 @@ install_requires = click Jinja2>=2.7 Markdown - Pillow>=4.0.0 + Pillow>=8.0.0 pilkit natsort From ce40d846fe44398d0ee89d0dd2dea07ca5b50c21 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 2 Aug 2022 17:15:51 +0200 Subject: [PATCH 4/4] Handle deprecation --- sigal/image.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sigal/image.py b/sigal/image.py index fafab13..99fc21e 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -161,10 +161,16 @@ def generate_thumbnail( img = Transpose().process(img) original_format = img.format + try: + method = PILImage.Resampling.LANCZOS + except AttributeError: + # Deprecated since version 9.1.0 + method = PILImage.ANTIALIAS + if fit: - img = ImageOps.fit(img, box, PILImage.Resampling.LANCZOS, centering=thumb_fit_centering) + img = ImageOps.fit(img, box, method, centering=thumb_fit_centering) else: - img.thumbnail(box, PILImage.Resampling.LANCZOS) + img.thumbnail(box, method) outformat = img.format or original_format or 'JPEG' logger.debug('Save thumnail image: %s (%s)', outname, outformat)