News for hackers. Stuff that matters.
Re:BlurHash: Algorithm to generate compact representation of... by smlacy on Thursday February 20, 2020 @09:44AM (#22375390)
Forgot to mention one important detail: How big is the JavaScript source to the BlurHash decoding algorithm?

I'm guessing that it's approximately the size of a single image, possibly quite a bit more.

Re:BlurHash: Algorithm to generate compact representation of... by switz on Thursday February 20, 2020 @11:46AM (#22376355)
1.9kB, minified and gzipped. Well within the parameters for cost savings.

https://bundlephobia.com/[email protected]

Re:BlurHash: Algorithm to generate compact representation of... by DagAgren on Thursday February 20, 2020 @10:21AM (#22375641)
The algorithm is tiny, and will easily fit in less than an image's worth of data, especially if you minify it. Also, it is likely you have more than one image on any given website.
Re:BlurHash: Algorithm to generate compact representation of... by lvh on Thursday February 20, 2020 @09:56AM (#22375446)
This is a great point! I wonder if it could be made much smaller by instead "vectorizing" the blur. Right now it appears to draw individual pixels, but perhaps it could draw a few large blurred gradiented circles instead?

(I also appreciate that this is probably me getting overexcited about this, since odds are the JS is cached, and in the case of mobile apps it doesn't matter much.)

Re:BlurHash: Algorithm to generate compact representation of... by sudhirj on Thursday February 20, 2020 @10:12AM (#22375574)
There's a pretty awesome project that does this with SVGs.

https://pkg.go.dev/mod/github.com/fogleman/primitive https://primitive.lol/

I've used it in a project to generate vector thumbnails that are under 1KB that I can just base64 encode and send along with the general text of a page - so the page renders with the text and low-fi images, and then I can load the hi-fi ones as necessary.

The lo-fi images are art in themselves, sometimes I preferred them to the actual images :-P

Re:BlurHash: Algorithm to generate compact representation of... by darkmighty on Thursday February 20, 2020 @02:02PM (#22377613)
The image animation (with randomized recreations) gives an amazing effect. I've never seen this technique before.

Like cinemagraphs, but unique and alive in a nice way.

http://i.imgur.com/Cb4ecUC.gifv

Re:BlurHash: Algorithm to generate compact representation of... by DagAgren on Thursday February 20, 2020 @10:26AM (#22375683)
That looks great!

You could probably devise a much smaller data representation too, to get the size down.

Re:BlurHash: Algorithm to generate compact representation of... by sudhirj on Thursday February 20, 2020 @09:55PM (#22380593)
Yeah, most of the size is the SVG XML cruft. The encoder uses only one kind of svg element with a standard set of attributes, so yeah, absolutely.
Re:BlurHash: Algorithm to generate compact representation of... by hombre_fatal on Thursday February 20, 2020 @09:51AM (#22375422)
22kb

Edit: Nevermind, derp, https://blurha.sh/blurhash.01ae00eea611ada5e9c7.js contains all of the JS of the entire website.

Re:BlurHash: Algorithm to generate compact representation of... by lvh on Thursday February 20, 2020 @10:08AM (#22375541)
Ironically jpegoptim is pretty happy to knock img1.jpg (woman eating donut) down from its original 55kB to 33kB with no perceptible-to-me quality loss though ;)
Re:BlurHash: Algorithm to generate compact representation of... by DagAgren on Thursday February 20, 2020 @10:41AM (#22375792)
It is a lot smaller than that, that is probably the size of all JS code on the web page?

The algorithm itself fits into a few k.

Re:BlurHash: Algorithm to generate compact representation of... by hombre_fatal on Thursday February 20, 2020 @11:36AM (#22376271)
Yeah, you're right. I found the first JS file in my network tab and judged by its blurhash.js filename that it was the algorithm: https://blurha.sh/blurhash.01ae00eea611ada5e9c7.js

Of course, my first clue should have been that it was also the only Javascript file.