Move to Pillow 10.x (#5489)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Ilia Sotnikov 2023-10-09 03:47:52 +03:00 committed by GitHub
parent e09c217fde
commit 412a866de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 15 deletions

View File

@ -151,7 +151,7 @@ async def to_code(config):
pos = 0
for frameIndex in range(frames):
image.seek(frameIndex)
frame = image.convert("LA", dither=Image.NONE)
frame = image.convert("LA", dither=Image.Dither.NONE)
if CONF_RESIZE in config:
frame = frame.resize([width, height])
pixels = list(frame.getdata())
@ -259,7 +259,7 @@ async def to_code(config):
if transparent:
alpha = image.split()[-1]
has_alpha = alpha.getextrema()[0] < 0xFF
frame = image.convert("1", dither=Image.NONE)
frame = image.convert("1", dither=Image.Dither.NONE)
if CONF_RESIZE in config:
frame = frame.resize([width, height])
if transparent:

View File

@ -67,18 +67,13 @@ def validate_pillow_installed(value):
except ImportError as err:
raise cv.Invalid(
"Please install the pillow python package to use this feature. "
'(pip install pillow">4.0.0,<10.0.0")'
'(pip install "pillow==10.0.1")'
) from err
if version.parse(PIL.__version__) < version.parse("4.0.0"):
if version.parse(PIL.__version__) != version.parse("10.0.1"):
raise cv.Invalid(
"Please update your pillow installation to at least 4.0.x. "
'(pip install pillow">4.0.0,<10.0.0")'
)
if version.parse(PIL.__version__) >= version.parse("10.0.0"):
raise cv.Invalid(
"Please downgrade your pillow installation to below 10.0.0. "
'(pip install pillow">4.0.0,<10.0.0")'
"Please update your pillow installation to 10.0.1. "
'(pip install "pillow==10.0.1")'
)
return value

View File

@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import core, pins
from esphome.components import display, spi
from esphome.components import display, spi, font
from esphome.core import CORE, HexInt
from esphome.const import (
CONF_COLOR_PALETTE,
@ -84,6 +84,7 @@ def _validate(config):
CONFIG_SCHEMA = cv.All(
font.validate_pillow_installed,
display.FULL_DISPLAY_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(ili9XXXSPI),
@ -162,7 +163,7 @@ async def to_code(config):
x = x + i.width
# reduce the colors on combined image to 256.
converted = ref_image.convert("P", palette=Image.ADAPTIVE, colors=256)
converted = ref_image.convert("P", palette=Image.Palette.ADAPTIVE, colors=256)
# if you want to verify how the images look use
# ref_image.save("ref_in.png")
# converted.save("ref_out.png")

View File

@ -255,7 +255,11 @@ async def to_code(config):
transparent = config[CONF_USE_TRANSPARENCY]
dither = Image.NONE if config[CONF_DITHER] == "NONE" else Image.FLOYDSTEINBERG
dither = (
Image.Dither.NONE
if config[CONF_DITHER] == "NONE"
else Image.Dither.FLOYDSTEINBERG
)
if config[CONF_TYPE] == "GRAYSCALE":
image = image.convert("LA", dither=dither)
pixels = list(image.getdata())

View File

@ -1,3 +1,3 @@
pillow>4.0.0,<10.0.0
pillow==10.0.1
cairosvg>=2.2.0
cryptography>=2.0.0,<4

View File

@ -760,6 +760,11 @@ image:
file: mdi:alert-outline
type: BINARY
font:
- file: "gfonts://Roboto"
id: roboto
size: 20
graph:
- id: my_graph
sensor: ha_hello_world_temperature