File MapProxy-pr750-Pillow10.patch of Package failed_python-MapProxy
diff --git a/mapproxy/compat/image.py b/mapproxy/compat/image.py
index e88bbc41..3732b890 100644
--- a/mapproxy/compat/image.py
+++ b/mapproxy/compat/image.py
@@ -26,6 +26,7 @@ try:
Image, ImageColor, ImageDraw, ImageFont, ImagePalette, ImageChops, ImageMath
ImageFileDirectory_v2, TiffTags
PIL_VERSION = getattr(PIL, '__version__') or getattr(PIL, 'PILLOW_VERSION')
+ PIL_VERSION_TUPLE = tuple(int(i) for i in PIL_VERSION.split("."))
except ImportError:
# allow MapProxy to start without PIL (for tilecache only).
# issue warning and raise ImportError on first use of
diff --git a/mapproxy/image/message.py b/mapproxy/image/message.py
index 4353e590..e40e53df 100644
--- a/mapproxy/image/message.py
+++ b/mapproxy/image/message.py
@@ -281,8 +281,14 @@ class TextDraw(object):
boxes = []
y_offset = 0
for i, line in enumerate(self.text):
- text_size = draw.textsize(line, font=self.font)
- text_box = (0, y_offset, text_size[0], text_size[1]+y_offset)
+ try:
+ text_box = draw.textbbox((0, y_offset), line, font=self.font)
+ y_offset = text_box[3] + self.linespacing
+ except AttributeError:
+ # Pillow < 8
+ text_size = draw.textsize(line, font=self.font)
+ text_box = (0, y_offset, text_size[0], text_size[1]+y_offset)
+ y_offset += text_size[1] + self.linespacing
boxes.append(text_box)
total_bbox = (min(total_bbox[0], text_box[0]),
min(total_bbox[1], text_box[1]),
@@ -290,7 +296,7 @@ class TextDraw(object):
max(total_bbox[3], text_box[3]),
)
- y_offset += text_size[1] + self.linespacing
+
return total_bbox, boxes
def _move_bboxes(self, boxes, offsets):
diff --git a/mapproxy/test/unit/test_image.py b/mapproxy/test/unit/test_image.py
index f2ea15ec..d4b62468 100644
--- a/mapproxy/test/unit/test_image.py
+++ b/mapproxy/test/unit/test_image.py
@@ -21,7 +21,7 @@ from io import BytesIO
import pytest
-from mapproxy.compat.image import Image, ImageDraw, PIL_VERSION
+from mapproxy.compat.image import Image, ImageDraw, PIL_VERSION_TUPLE
from mapproxy.image import (
BlankImageSource,
GeoReference,
@@ -112,7 +112,7 @@ class TestImageSource(object):
assert is_tiff(ir.as_buffer(TIFF_FORMAT))
assert is_tiff(ir.as_buffer())
- @pytest.mark.skipif(PIL_VERSION < '6.1.0', reason="Pillow 6.1.0 required GeoTIFF")
+ @pytest.mark.skipif(PIL_VERSION_TUPLE < (6, 1, 0), reason="Pillow 6.1.0 required GeoTIFF")
def test_tiff_compression(self):
def encoded_size(encoding_options):
ir = ImageSource(create_debug_img((100, 100)), PNG_FORMAT)
@@ -134,7 +134,7 @@ class TestImageSource(object):
assert q50 > lzw
@pytest.mark.xfail(
- PIL_VERSION >= '9.0.0',
+ PIL_VERSION_TUPLE >= (9, 0, 0),
reason="The palette colors order has been changed in Pillow 9.0.0"
)
def test_output_formats_greyscale_png(self):
@@ -156,7 +156,7 @@ class TestImageSource(object):
assert img.getpixel((0, 0)) == (0, 0)
@pytest.mark.xfail(
- PIL_VERSION >= '9.0.0',
+ PIL_VERSION_TUPLE >= (9, 0, 0),
reason="The palette colors order has been changed in Pillow 9.0.0"
)
def test_output_formats_png8(self):
@@ -593,7 +593,7 @@ def assert_geotiff_tags(img, expected_origin, expected_pixel_res, srs, projected
assert tags[TIFF_GEOKEYDIRECTORYTAG][3*4+3] == srs
-@pytest.mark.skipif(PIL_VERSION < '6.1.0', reason="Pillow 6.1.0 required GeoTIFF")
+@pytest.mark.skipif(PIL_VERSION_TUPLE < (6, 1, 0), reason="Pillow 6.1.0 required GeoTIFF")
@pytest.mark.parametrize("compression", ['jpeg', 'raw', 'tiff_lzw'])
class TestGeoTIFF(object):