Repository navigation
feat: BlurHash placeholders (image.blurhash, decodeBlurhash, fm=blurhash) - #1567
Merged
Merged
Conversation
image.blurhash({ componentsX, componentsY }) encodes a BlurHash (default
4x3) and decodeBlurhash(hash, { w, h, punch }) turns one back into a bitmap
for Jimp.fromBitmap or a canvas ImageData. The algorithm is in-house and
matches the reference blurhash package exactly; large images are scaled to
64px first, transparent pixels are drawn over image.background, and other
colour spaces are converted to sRGB.
@jimp/server gets fm=blurhash, which responds with the edited image's hash
as text/plain. Docs pages, a playground op and type tests are included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hipstersmoothie
force-pushed
the
sesh/blurhash-placeholders
branch
from
November 25, 2026 03:38
1c92dc4 to
9455762
Compare
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 BlurHash encoding and decoding to
@jimp/plugin-hash, for tiny image placeholders.API
image.blurhash(options?): a value-returning plugin method, likehash/pHash. Options are a zod schema;componentsX/componentsYare whole numbers from 1 to 9, defaulting to 4 and 3.decodeBlurhash(hash, { w, h, punch? }): exported from the plugin and re-exported fromjimp, likedistance/compareHashes. It returns{ data: Uint8ClampedArray, width, height }, which fits bothJimp.fromBitmapand a canvasImageDatawithout a copy. Plugins don't add statics to the Jimp class, so this is a function rather than a factory.BlurhashOptionsandDecodeBlurhashOptionsare exported fromjimp.apply()and@jimp/workerneed no changes.JimpEditalready drops methods that don't return the image, andapplythrows at runtime. Type tests now coverblurhash.Implementation
plugins/plugin-hash/src/blurhash.ts. It follows the reference TS package's arithmetic step by step, including the order of sums and products, so the strings match to the character. It encodes in one pass over the pixels for all components, with cosine and sRGB-to-linear lookup tables.resizefirst, without copying the full-size pixels. A 10000×783 JPEG encodes in about 30 ms.image.background, the same rulegetBufferuses for JPEG.@jimp/server:fm=blurhashThis was small, so it's implemented.
?fm=blurhashruns the other params as usual, then responds with the hash astext/plain; charset=utf-8. It gets the same ETag and Cache-Control as image responses, and HEAD works. As with formats without alpha, transparent pixels are drawn over white unlessbgis set. A Jimp class withoutblurhashgets a 415.Docs
blurhashanddecode-blurhash, in "Loading & saving", registered inmethods.ts.blurhashplayground op in its ownops/placeholder.ts, which also gives the OG card a preview.Tests
plugins/plugin-hash/src/blurhash.test.tscompares against the referenceblurhashpackage (new devDependency).image.blurhash()matches the reference for images up to 64px, and for the reference run on the same 64px resize.fm=blurhash, HEAD,bg, and the 415.pnpm build(including the browser bundle check),pnpm lint, the plugin-hash, jimp (including type tests) and server suites, and the docs build.Worth a look
blurhashpackage takes the AC maximum withoutabs(), while the C and Swift encoders use the magnitude. I copied the TS behaviour so strings match that package. Its decoder also doespunch | 1, so 1.5 becomes 3. We usepunchas given, and the docs say so.image.backgroundis transparent, so fully transparent pixels turn black, the same as JPEG output. The docs and playground recommend settingimage.background. The server defaults to white.fm=blurhashdoesn't take component params yet.🤖 Generated with Claude Code