fix: letterbox image to exact target size when fitscreen is false - #175
Open
kjames2001 wants to merge 1 commit into
Open
fix: letterbox image to exact target size when fitscreen is false#175kjames2001 wants to merge 1 commit into
kjames2001 wants to merge 1 commit into
Conversation
image_to_rgb565 with fitscreen=False used only PIL thumbnail(), which preserves aspect ratio and returns an image smaller than the requested box whenever the source aspect differs from the box (e.g. a square cover pushed into a wide 400x160 object). The plate decodes the RGB565 payload using the width in the header as the row stride, so a pushed image narrower than the object box renders doubled/split (a '1.5 image') instead of centered. Letterbox the thumbnail onto a black canvas at the exact target size so the pushed width always matches the object width. Sources smaller than the box keep the existing no-upscale behaviour (unchanged output).
fvanroie
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
push_imageis called withfitscreenfalse (the default) and thesource image's aspect ratio differs from the requested
width/height,image_to_rgb565usesPIL.Image.thumbnail(), which preserves aspectratio and returns an image smaller than the requested box.
Example: a square 512x512 cover pushed into a 400x160 object is
thumbnail-scaled to 160x160, not 400x160.
The plate decodes the RGB565 payload using the width stored in the
header as the row stride. A pushed image narrower than the object box
therefore renders doubled / split (the top of the image repeated,
second copy cut off — a "1.5 image") instead of centered. 16:9 sources
into 16:9 boxes are unaffected, which is why cameras usually look fine
while square covers glitch.
Fix
After
thumbnail(), paste the result onto a black canvas at the exacttarget size (centered). The pushed width now always matches the object
width, which is what the plate's decoder expects.
(the
min()clamp is unchanged; output identical to before).fitscreen=Truepath (ImageOps.fit) is untouched.Verification
image_to_rgb565across: square->wide box,16:9->16:9 box (196x110 / 400x160 / 480x270), small source, exact
size, RGBA source, and the fitscreen path — all outputs carry the
expected width/height header.
480x480): the doubled image no longer appears; the rendered box is
pixel-identical to the expected letterboxed frame (max channel diff 5).
black --checkclean.