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

View file

@ -67,18 +67,13 @@ def validate_pillow_installed(value):
except ImportError as err: except ImportError as err:
raise cv.Invalid( raise cv.Invalid(
"Please install the pillow python package to use this feature. " "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 ) 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( raise cv.Invalid(
"Please update your pillow installation to at least 4.0.x. " "Please update your pillow installation to 10.0.1. "
'(pip install pillow">4.0.0,<10.0.0")' '(pip install "pillow==10.0.1")'
)
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")'
) )
return value return value

View file

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

View file

@ -255,7 +255,11 @@ async def to_code(config):
transparent = config[CONF_USE_TRANSPARENCY] 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": if config[CONF_TYPE] == "GRAYSCALE":
image = image.convert("LA", dither=dither) image = image.convert("LA", dither=dither)
pixels = list(image.getdata()) 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 cairosvg>=2.2.0
cryptography>=2.0.0,<4 cryptography>=2.0.0,<4

View file

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