14
0

Accepting request 1114989 from home:mcalabkova:branches:devel:languages:python

- Add upstream pillow10.patch to fix compatibility with Pillow 10.0.0

OBS-URL: https://build.opensuse.org/request/show/1114989
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-blockdiag?expand=0&rev=24
This commit is contained in:
2023-10-03 12:53:11 +00:00
committed by Git OBS Bridge
parent 8f809b21cb
commit 833255b998
3 changed files with 124 additions and 0 deletions

117
pillow10.patch Normal file
View File

@@ -0,0 +1,117 @@
From 20d780cad84e7b010066cb55f848477957870165 Mon Sep 17 00:00:00 2001
From: Theodore Ni <3806110+tjni@users.noreply.github.com>
Date: Sat, 5 Aug 2023 10:43:46 -0700
Subject: [PATCH] Add support for Pillow 10
Fix a bunch of breaking changes in a backwards compatible way.
---
src/blockdiag/imagedraw/png.py | 47 ++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 8 deletions(-)
diff --git a/src/blockdiag/imagedraw/png.py b/src/blockdiag/imagedraw/png.py
index 3cac05a..12f0514 100644
--- a/src/blockdiag/imagedraw/png.py
+++ b/src/blockdiag/imagedraw/png.py
@@ -30,6 +30,21 @@
from blockdiag.utils.myitertools import istep, stepslice
+# to support pillow < 9.1.0
+if not hasattr(Image, 'Resampling'):
+ from enum import IntEnum
+
+ class Resampling(IntEnum):
+ NEAREST = 0
+ BOX = 4
+ BILINEAR = 2
+ HAMMING = 5
+ BICUBIC = 3
+ LANCZOS = 1
+
+ Image.Resampling = Resampling
+
+
def point_pairs(xylist):
iterable = iter(xylist)
for pt in iterable:
@@ -147,7 +162,7 @@ def set_canvas_size(self, size):
self.draw = ImageDraw.Draw(self._image)
def resizeCanvas(self, size):
- self._image = self._image.resize(size, Image.ANTIALIAS)
+ self._image = self._image.resize(size, Image.Resampling.LANCZOS)
self.draw = ImageDraw.Draw(self._image)
def arc(self, box, start, end, **kwargs):
@@ -273,13 +288,21 @@ def textfolder(self):
def textlinesize(self, string, font):
ttfont = ttfont_for(font)
if ttfont is None:
- size = self.draw.textsize(string, font=None)
+ if hasattr(self.draw, 'textbbox'):
+ left, top, right, bottom = self.draw.textbbox((0, 0), string)
+ size = (right - left, bottom - top)
+ else:
+ size = self.draw.textsize(string, font=None)
font_ratio = font.size * 1.0 / FontMap.BASE_FONTSIZE
size = Size(int(size[0] * font_ratio),
int(size[1] * font_ratio))
else:
- size = Size(*ttfont.getsize(string))
+ if hasattr(ttfont, 'getbbox'):
+ left, top, right, bottom = ttfont.getbbox(string)
+ size = Size(right - left, bottom - top)
+ else:
+ size = Size(*ttfont.getsize(string))
return size
@@ -291,7 +314,11 @@ def text(self, xy, string, font, **kwargs):
if self.scale_ratio == 1 and font.size == FontMap.BASE_FONTSIZE:
self.draw.text(xy, string, fill=fill)
else:
- size = self.draw.textsize(string)
+ if hasattr(self.draw, 'textbbox'):
+ left, top, right, bottom = self.draw.textbbox((0, 0), string)
+ size = (right - left, bottom - top)
+ else:
+ size = self.draw.textsize(string)
image = Image.new('RGBA', size)
draw = ImageDraw.Draw(image)
draw.text((0, 0), string, fill=fill)
@@ -299,10 +326,14 @@ def text(self, xy, string, font, **kwargs):
basesize = (size[0] * self.scale_ratio,
size[1] * self.scale_ratio)
- text_image = image.resize(basesize, Image.ANTIALIAS)
+ text_image = image.resize(basesize, Image.Resampling.LANCZOS)
self.paste(text_image, xy, text_image)
else:
- size = ttfont.getsize(string)
+ if hasattr(ttfont, 'getbbox'):
+ left, top, right, bottom = ttfont.getbbox(string)
+ size = (right - left, bottom - top)
+ else:
+ size = ttfont.getsize(string)
# Generate mask to support BDF(bitmap font)
mask = Image.new('1', size)
@@ -370,7 +401,7 @@ def image(self, box, url):
# resize image.
w = min([box.width, image.size[0] * self.scale_ratio])
h = min([box.height, image.size[1] * self.scale_ratio])
- image.thumbnail((w, h), Image.ANTIALIAS)
+ image.thumbnail((w, h), Image.Resampling.LANCZOS)
# centering image.
w, h = image.size
@@ -404,7 +435,7 @@ def save(self, filename, size, _format):
y = int(self._image.size[1] / self.scale_ratio)
size = (x, y)
- self._image.thumbnail(size, Image.ANTIALIAS)
+ self._image.thumbnail(size, Image.Resampling.LANCZOS)
if self.filename:
self._image.save(self.filename, _format)

View File

@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Tue Oct 3 12:06:41 UTC 2023 - Markéta Machová <mmachova@suse.com>
- Add upstream pillow10.patch to fix compatibility with Pillow 10.0.0
------------------------------------------------------------------- -------------------------------------------------------------------
Wed May 3 11:50:50 UTC 2023 - Dirk Müller <dmueller@suse.com> Wed May 3 11:50:50 UTC 2023 - Dirk Müller <dmueller@suse.com>

View File

@@ -28,6 +28,8 @@ Source: https://files.pythonhosted.org/packages/source/b/blockdiag/block
# PATCH-FIX-UPSTREAM python-blockdiag-nose-to-pytest.patch gh#blockdiag/blockdiag#131 pgajdos@suse.com # PATCH-FIX-UPSTREAM python-blockdiag-nose-to-pytest.patch gh#blockdiag/blockdiag#131 pgajdos@suse.com
# Remove the last silly dependency on nose # Remove the last silly dependency on nose
Patch0: python-blockdiag-nose-to-pytest.patch Patch0: python-blockdiag-nose-to-pytest.patch
# PATCH-FIX-UPSTREAM https://github.com/blockdiag/blockdiag/pull/179 Add support for Pillow 10
Patch1: pillow10.patch
BuildRequires: %{python_module Pillow >= 3} BuildRequires: %{python_module Pillow >= 3}
BuildRequires: %{python_module base >= 3.7} BuildRequires: %{python_module base >= 3.7}
BuildRequires: %{python_module funcparserlib >= 1.0.0~a0} BuildRequires: %{python_module funcparserlib >= 1.0.0~a0}