Skip to content

trim - #67

Merged
matmen merged 1 commit into
masterfrom
trim
Oct 16, 2026
Merged

trim#67
matmen merged 1 commit into
masterfrom
trim

Conversation

@matmen

@matmen matmen commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Adds image.trim(color, options), which removes borders of one color, like the empty space around rendered text or a solid background around a logo:

Image.renderText(font, 64, 'Hi').trim();          // the transparent space around the text
logo.trim(0xffffffff, {tolerance: 0.05});         // a white background with JPEG artifacts
  • Without a color, the top left pixel's color is used. Fully transparent pixels count as one color, whatever their RGB values.
  • tolerance (0–1 per channel) also trims near colors.
  • Frames move their offsets by the trimmed amount, so the remaining pixels stay in place within the animation.
  • An image that is entirely the color is left as it is.

Tests in tests/trim.js.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ

trim(color, options) removes borders of one color: by default the top
left pixel's, fully transparent pixels count as one color whatever their
RGB values. A tolerance (0-1 per channel) also trims near colors, e.g.
JPEG artifacts. Frames move their offsets by the trimmed amount, so the
remaining pixels stay in place. An image of only the color is left as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ljnxm1Qjrocq1izGajLx8J
@matmen
matmen merged commit d641dbe into master Oct 16, 2026
13 checks passed
@matmen
matmen deleted the trim branch October 16, 2026 07:24
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.

1 participant