[FIX] core, web: Pillow 9.1 deprecations
Pillow 9.1 deprecates most if not all toplevel Image constants: https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#constants These constants have been moved to thematic enum classes (e.g. all the resampling constants in `PIL.Image.Resampling`). This triggers warnings in Odoo, and the removal delay is quite short (slated for Pillow 10, release planned mid 2023). Pillow 9.1 is also already in Debian Bookworm (current testing). Fix by shimming at the import level: if the enums are available import them into the local namespace, otherwise alias `PIL.Image` itself as to the enum. closes odoo/odoo#96799 X-original-commit: 7be04d31bad078681ef0a2919234c11840a2e8e2 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import markupsafe
|
||||
from PIL import Image
|
||||
from markupsafe import Markup
|
||||
|
||||
from odoo import api, fields, models, tools
|
||||
@@ -14,6 +13,10 @@ except ImportError:
|
||||
# If the `sass` python library isn't found, we fallback on the
|
||||
# `sassc` executable in the path.
|
||||
libsass = None
|
||||
try:
|
||||
from PIL.Image import Resampling
|
||||
except ImportError:
|
||||
from PIL import Image as Resampling
|
||||
|
||||
DEFAULT_PRIMARY = '#000000'
|
||||
DEFAULT_SECONDARY = '#000000'
|
||||
@@ -204,7 +207,7 @@ class BaseDocumentLayout(models.TransientModel):
|
||||
|
||||
# Converts to RGBA (if already RGBA, this is a noop)
|
||||
image_converted = image.convert('RGBA')
|
||||
image_resized = image_converted.resize((w, h), resample=Image.NEAREST)
|
||||
image_resized = image_converted.resize((w, h), resample=Resampling.NEAREST)
|
||||
|
||||
colors = []
|
||||
for color in image_resized.getcolors(w * h):
|
||||
|
||||
Reference in New Issue
Block a user