Skip to content

Metadata for every format - #56

Merged
matmen merged 1 commit into
masterfrom
encode-metadata
Oct 15, 2026
Merged

matmen merged 1 commit into
masterfrom
encode-metadata

Conversation

@matmen

@matmen matmen commented Oct 15, 2026

Copy link
Copy Markdown
Owner

All encoders now take the metadata encode() takes for PNGs. The interface is now called Metadata, PNGMetadata stays as a deprecated alias until 4.0.

Each format stores the fields it has a place for:

Format Stored in Fields
PNG, APNG text chunks all
JPEG Exif (APP1), comment marker author, description, copyright, creation time, software, comment
WebP (still and animated) Exif (EXIF chunk, extended format) author, description, copyright, creation time, software
GIF comment extensions software, comment
TGA TGA 2.0 extension area author, comment, creation time, software

Defaults

The defaults are the same for every format: the creation time, and ImageScript with its version as the software. {software: ''} leaves the software out.

Size added to each file: about 40 bytes for GIF, about 200 for JPEG and WebP, 495 for TGA (the extension area has a fixed size).

Fixes

  • PNG text that isn't Latin-1: it was written as UTF-8 into tEXt, which is Latin-1, so readers showed it garbled. It now goes into iTXt chunks as UTF-8.
  • PNG text chunks now come before the image data, where all readers look for them.
  • An invalid creationTime throws a RangeError instead of writing "Invalid Date".

Testing

  • New test: tests/metadata.js.
  • ExifTool 13.59 reads the JPEG, WebP, GIF, PNG and APNG fields without warnings.
  • Pillow reads all fields. Non-ASCII Exif text shows garbled there, because Pillow decodes Exif strings as Latin-1. ExifTool shows it correctly, and UTF-8 is the common practice for Exif strings.
  • TGA: ExifTool doesn't support TGA. The extension area was parsed by hand against the TGA 2.0 specification.

@matmen matmen self-assigned this Oct 15, 2026
@matmen matmen added the enhancement New feature or request label Oct 15, 2026
@matmen matmen added this to the v3.2.0 milestone Oct 15, 2026
All encoders take the metadata `encode()` takes for PNGs (`Metadata`,
`PNGMetadata` stays as a deprecated alias), each format stores the fields
it has a place for:
- JPEG: Exif (APP1) and a comment marker
- WebP: Exif (the extended format's EXIF chunk), still and animated
- GIF: comment extensions
- TGA: the TGA 2.0 extension area
- APNG: text chunks, like PNG

The defaults are the same everywhere: the creation time and ImageScript
with its version as the software (`software: ''` leaves it out).

PNG text that isn't Latin-1 goes into iTXt chunks as UTF-8 instead of
tEXt, and the text chunks come before the image data. An invalid creation
time throws instead of writing "Invalid Date".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ljnxm1Qjrocq1izGajLx8J
@matmen
matmen merged commit 9d7c5e4 into master Oct 15, 2026
13 checks passed
@matmen
matmen deleted the encode-metadata branch October 15, 2026 14:54
@matmen
matmen restored the encode-metadata branch October 15, 2026 14:54
@matmen
matmen deleted the encode-metadata branch October 15, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant