Skip to content

Expand image canvas to preserve wide barcode captions - #268

Open
ac1982 wants to merge 1 commit into
WhyNotHugo:mainfrom
ac1982:fix/image-caption-width
Open

ac1982 wants to merge 1 commit into
WhyNotHugo:mainfrom
ac1982:fix/image-caption-width

Conversation

@ac1982

@ac1982 ac1982 commented Oct 14, 2026

Copy link
Copy Markdown

GS1-128's compact numeric encoding can make the bars narrower than their human-readable caption. For example, Gs1_128("00376401856400470087", writer=ImageWriter()).render() creates a 428-pixel-wide image at the default settings, clipping both ends of a caption that needs about 494 pixels.

Measure text bounds in ImageWriter and expand its canvas horizontally when needed. Move the existing pixels together so module sizes and the relative positions of the bars and caption blocks stay intact. Reset the translation for each render. Add pixel comparisons for multiline captions, both text positions, guarded EAN text blocks, transparent backgrounds, and writer reuse; document the possible increase in image width.

Fixes #229. This addresses horizontal clipping in ImageWriter; #212's vertical size/text-distance changes are independent.

Validation:

  • New regressions on the base revision: 10 failed, 1 passed. Full suite after the fix: 66 passed (Python 3.12.15, Pillow 12.3.0).
  • Without Pillow: 53 passed on Python 3.14.4.
  • Actual CLI PNG generation and independent zbar decoding of GS1-128 and guarded EAN-13 preserve the encoded values. Barcode pixel comparisons preserve module geometry.
  • Ruff 0.11.9 lint/format, Vermin compatibility check, and diff checks pass.
  • Mypy reports the same 13 pre-existing errors before and after. Sphinx builds successfully with the same three existing warnings. The full CI Python matrix was not run locally.

AI-assisted implementation and validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GS1-128 images are cut-off

1 participant