Repository navigation
feat(core): apply() runs a list of edits stored as data - #1558
Merged
Merged
Conversation
image.apply([["resize", { w: 100 }], ["greyscale"]]) runs plugin methods
from a list of [name, ...args] tuples, so edits can be stored as JSON, sent
to a server or worker, and applied later. Names are checked before any edit
runs; only plugin methods that return the image are allowed. JimpEdit types
each edit from the image type, so the declaration stays one line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 25, 2026
Collaborator
Author
|
🚀 PR was released in |
70B5
div>
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.
Adds
image.apply(edits), which runs a list of[methodName, ...args]edits in order:Because the list is plain data, it can be stored as JSON, kept as a preset, or sent to a server or worker and applied there. It's the foundation for the planned
@jimp/server(image transforms from URL params) and@jimp/worker(running edits off the main thread).Design
[name, ...args]. Every plugin method takes(image, options?), so most edits are[name]or[name, options]. Tuples also cover positional arguments such as["blur", 2].write,getBuffer,clone,composite,scan, …) and inherited properties (constructor,__proto__) are rejected by name, so a recipe can't touch the filesystem. Methods that return a value (hash,pHash,distanceFromHash,autocropRect) are type errors, and throw at runtime when reached.Edit 1 (resize) failed: …, with the original error ascause.JimpEdit<Image>in@jimp/corederives edits from the instance type, andjimpexportsJimpEditfor the default class. Deriving it from the plugin method map instead doubledjimp'sindex.d.ts: tsc inlined the whole map in each of the 12 places the class type repeats. This way the emitted declaration is one line:apply<S extends JimpClass>(this: S, edits: CoreJimpEdit<S>[]): S.Docs
/methods/apply/Tests
packages/jimp/src/apply.test.ts: results match chaining, JSON round-trips, validation and error messages, custom classes, and every default plugin name being accepted.packages/jimp/src/apply.test-d.ts: argument checking, exclusion of core methods and value-returning methods, custom-class plugins, and thatJimpEditnames only plugin methods.🤖 Generated with Claude Code