Skip to content

Fixed PNG chunk stripping breaking image validation#54

Merged
ikraamg merged 1 commit intomainfrom
claude/issue-47-20260329-1055
Apr 15, 2026
Merged

Fixed PNG chunk stripping breaking image validation#54
ikraamg merged 1 commit intomainfrom
claude/issue-47-20260329-1055

Conversation

@ikraamg
Copy link
Copy Markdown
Collaborator

@ikraamg ikraamg commented Apr 15, 2026

The TRMNL device image validation rejected grayscale PNGs with "First two header bytes are invalid" because two layers of chunk stripping were active in the pipeline: png:exclude-chunks=all in configureOutputFormat and an unconditional .strip() in applyDithering.

Fixes #47

The TRMNL device firmware rejected grayscale PNGs with "First two
header bytes are invalid" because two layers of chunk stripping were
active in the pipeline: `png:exclude-chunks=all` in configureOutputFormat
and an unconditional `.strip()` in applyDithering. Together they
produced PNGs containing only IHDR, IDAT, and IEND. The PNG spec
marks these as sufficient, but the firmware parser needs ancillary
chunks (bKGD in particular), so the misleading error was a symptom of
missing chunks further into the file — not the signature itself.

Removed the exclude-chunks directive entirely and scoped `.strip()` to
non-PNG formats. The full saving from chunk stripping was ~170 bytes
on a typical 800x480 image — under 0.5% of the 50KB budget — which is
not worth the firmware compatibility risk. `.strip()` still runs for
JPEG/BMP where it removes larger ICC profiles and EXIF. The shared
`png:compression-level` define was hoisted out of the if/else in
configureOutputFormat since both branches set it identically.

Locked the fix in with three tests per grayscale palette: valid PNG
signature, required IHDR/IDAT/IEND chunks, and at least one ancillary
chunk beyond the three-chunk minimum. The ancillary assertion checks
`chunks.length > 3` rather than hard-coding a specific chunk name so
it stays robust across ImageMagick version changes that might swap
which default chunks get emitted.

Fixes #47

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ikraamg ikraamg changed the title Fixed PNG chunk stripping breaking TRMNL firmware Fixed PNG chunk stripping breaking TRMNL validation Apr 15, 2026
@ikraamg ikraamg changed the title Fixed PNG chunk stripping breaking TRMNL validation Fixed PNG chunk stripping breaking image validation Apr 15, 2026
@ikraamg ikraamg marked this pull request as ready for review April 15, 2026 13:13
@ikraamg ikraamg merged commit 3680950 into main Apr 15, 2026
8 checks passed
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.

PNG images rejected by TRMNL device due to png:exclude-chunks=all stripping critical chunks

1 participant