Repository navigation
feat: gradientMap() for duotones and gradient maps - #1564
Merged
Merged
Conversation
…utils Move ColorSchema, GradientStop and gradient sampling from plugin-draw into @jimp/utils so other plugins can describe and sample gradients the same way. Stops can now be bare colors, spread out evenly, in plugin-draw gradients as well as layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…maps image.gradientMap(stops) replaces each pixel with the color at its luminance along a gradient; two stops make a duotone. Stops are the shared GradientStops that plugin-draw and layout gradients take. Luminance is the Rec. 709 luma greyscale() uses, and colors are interpolated in the image's stored (gamma encoded) space like CSS and plugin-draw gradients. Alpha is kept, multiplied by the gradient's alpha, and amount blends with the original. It's in @jimp/server's default allowed edits, and has a docs page with a playground op and example images. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
🚀 PR was released in |
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.gradientMap(): each pixel's luminance is mapped through a list of colour stops. Two stops give a duotone, the Spotify-style look for OG images.Changes
refactor: share gradient stops(first commit, so the grain/gradient-dithering branch can rebase onto it)ColorSchema/Color,GradientStopSchema/GradientStop,GradientStopsSchema/GradientStops,normalizeStops,resolveColorandgradientTablemove fromplugin-draw/src/paint.tsto a new@jimp/utilsfile,gradient.ts. The code is the same;gradientTablenow takes aColorSpaceand asize.plugin-drawre-exports the types, sojimp's exports don't change.plugin-draw,@jimp/layoutandgradientMapnow all take the same stops:{ offset, color }, or bare colours spread out evenly. Layout already allowed bare colours; draw gradients now accept them too. Layout's stop colours now also accept{ r, g, b, a }, and its stop objects are no longer strict.@jimp/utilsgains azoddependency (lockfile updated).feat(plugin-color): add gradientMapplugin-color, next tosepia. Options are a zod schema (GradientMapOptions, exported fromjimp). Invalid colours throwInvalid color "...".apply()and@jimp/workerneed no registration: they call any plugin method.@jimp/serverhas an allowlist, sogradientMapis added todefaultAllowedEdits.methods/gradient-map.mdxpage with example images (made byscripts/gradient-map-images.mjs), a playground op (shadows / optional midtone / highlights / amount), amethods.tsentry, a note in the drawing concepts page that bare-colour stops are accepted, and the custom-jimp plugin table.Design decisions
greyscale()uses (on the stored, gamma-encoded values, rounded). SogradientMap(img)equalsgradientMap(img.greyscale()), and black→white on a grey ramp leaves it unchanged (both are tested).gradientTableasplugin-draw. That matches CSS gradients' default and Jimp's drawn gradients. CSS colours are converted to the image's space (P3 is tested). Linear-light interpolation, asexposureuses, was the other option. I didn't take it, so that stops look like the same stops 8000 drawn as a gradient.amount(0–1, default 1, clamped likesepia) linearly blends all four channels with the original.duotonemethod: the docs show duotone as a two-stop example.Testing
pnpm exec vitest runin utils, plugin-draw, plugin-color, layout, server, worker and jimp (node + type tests) all pass. There are new pixel-exact tests and two image snapshots.pnpm buildpasses, including the browser bundle check.pnpm lintpasses. The docsastro check+ build pass.🤖 Generated with Claude Code