csscss-gradients

Is it possible to convert Blurhash string to CSS gradients?


I'm currently interested in Blurhash, which can be used as user-friendly placeholder for image loading, to convert the given hash into a set of CSS gradient background, so I may use it as a placeholder like:

{
  background: radial-gradient(...) linear-gradient(...); /* converted Blurhash representation */
  background: url('/path/to/image.jpg');
}

or:

<img src="/path/to/image.png" style="background: radial-gradient(...) linear-gradient(...);">

I know that it is currently possible to use these hashes on web, and there's also an official TypeScript implementation, but the library only returns the decoded hash in terms of pixels (or HTML <canvas> data).

Are there any library that can convert these data into CSS gradient instructions?


Solution

  • I have been looking into this myself recently. Here are some of the solutions I found: