Skip to content
Toolcroft

Image Tools

BlurHash Generator - Compact Image Placeholder

Generate a BlurHash string from any image. BlurHash encodes a blurred image preview as a short ASCII string (typically 20–30 chars) for use as a placeholder while the real image loads.

What is BlurHash?

BlurHash was created by Dag Agren at Wolt. It uses a DCT (Discrete Cosine Transform) to encode the low-frequency components of an image into a compact base83 string. Because only low frequencies are stored, the result is always a blurry preview - never a recognisable reproduction of private content.

Integration examples

The hash string can be decoded in the browser using the blurhash npm package, or on the server using Swift/Kotlin/Go libraries. Frameworks like Next.js Image and Astro also support BlurHash placeholders.

X and Y component parameters

The X and Y component values control how much spatial detail is encoded in the hash, and directly affect the length of the output string:

Components (X × Y)Hash length (approx.)Detail levelTypical use
2 × 2~20 charsMinimal - solid color gradientTiny thumbnails, avatar placeholders
4 × 3~30 charsDefault - recognizable blurGeneral images, blog photos
6 × 4~40 charsGood - distinct shapes visibleHero images, product photos
8 × 6~55 charsHigh - fine detail in blurWhen longer hash is acceptable

Higher component counts produce longer hash strings but more detailed blurs. The tradeoff between string length and visual quality peaks around 4×3 for most images - additional components add length with diminishing returns in perceived quality.

Performance impact

Decoding a BlurHash and rendering it to a canvas takes under 1 millisecond in JavaScript for typical component counts. The recommended implementation is:

  1. Render the decoded BlurHash as a CSS background-image on a container element.
  2. Load the real image behind it with loading="lazy".
  3. Once the image loads, fade out the BlurHash canvas or remove it from the DOM.

This approach eliminates layout shift (the space is pre-occupied) and provides a visually pleasant loading experience with near-zero performance overhead.