New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(media): Blurhash #1381
feat(media): Blurhash #1381
Changes from 2 commits
75b7ab6
7dd3ac2
219ff37
4dc5a46
ddef2dd
2bebfdd
a1f5096
dcb0c69
fdef73b
0562e66
f8f479d
8f25d11
5aa04d6
f080728
ba9c396
557176f
dc1d11e
f0306e5
7af9278
39c24ea
20a6ee8
66c829a
421af34
b711fb6
fa00e04
6ec0d28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { decode as decodeBlurHash } from 'blurhash' | ||
|
||
let canvas | ||
|
||
export function decode (blurhash) { | ||
const pixels = decodeBlurHash(blurhash, 320, 320) | ||
|
||
if (pixels) { | ||
canvas = canvas || document.createElement('canvas') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mastodon renders the canvases directly but I though that it's too much overhead to create and destroy that many canvases so I went with this approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, so the problem with |
||
const imageData = new window.ImageData(pixels, 320, 320) | ||
canvas.getContext('2d').putImageData(imageData, 0, 0) | ||
return canvas.toDataURL() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could try https://github.com/fpapado/blurhash-rust-wasm if performance turns out to be an issue.