Fix frame scaling for animated gifs (#2750)

This commit is contained in:
Dave T 2021-11-18 22:20:32 +00:00 committed by GitHub
parent 9e1c3e8f01
commit e5cb5756aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,6 +60,10 @@ async def to_code(config):
image.seek(frameIndex)
frame = image.convert("L", dither=Image.NONE)
pixels = list(frame.getdata())
if len(pixels) != height * width:
raise core.EsphomeError(
f"Unexpected number of pixels in frame {frameIndex}: {len(pixels)} != {height*width}"
)
for pix in pixels:
data[pos] = pix
pos += 1
@ -69,8 +73,14 @@ async def to_code(config):
pos = 0
for frameIndex in range(frames):
image.seek(frameIndex)
if CONF_RESIZE in config:
image.thumbnail(config[CONF_RESIZE])
frame = image.convert("RGB")
pixels = list(frame.getdata())
if len(pixels) != height * width:
raise core.EsphomeError(
f"Unexpected number of pixels in frame {frameIndex}: {len(pixels)} != {height*width}"
)
for pix in pixels:
data[pos] = pix[0]
pos += 1