Decoding #188
Replies: 10 comments 2 replies
-
A slight modification of the JS implementation could do that, however the base64 encoded png version of the blurred image is much larger than the blurhash (defeating the purpose of decreasing network load). Here's what you would use if you wanted to pursue this: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL |
Beta Was this translation helpful? Give feedback.
-
@patrick-mcdougle I mean, the API would return the blurhash, but I don't want to rely on canvas because of environment you know? |
Beta Was this translation helpful? Give feedback.
-
@andreyvital If you're looking for a react native implementation, I've just written one at https://github.com/mrousavy/react-native-blurhash |
Beta Was this translation helpful? Give feedback.
-
@andreyvital did you find the solution? |
Beta Was this translation helpful? Give feedback.
-
This might help: import { decode } from 'blurhash'
import { getImgFromArr } from 'array-to-image'
const pixels = decode('LEHV6nWB2yk8pyo0adR*.7kCMdnj', 32, 32) // Uint8ClampedArray
const image = getImgFromArr(pixels, 32, 32) // HTMLImageElement
const src = image.src // data:image/png;base64,iVBORw0KGgoAA... |
Beta Was this translation helpful? Give feedback.
-
This does not answers OP question because it uses canvas. |
Beta Was this translation helpful? Give feedback.
-
+1 on this, would love if anyone has a solution. Currently trying to implement the EDIT I ended up finding react-blurhash, which works really well in lieu of a pure server-side Node.js solution. |
Beta Was this translation helpful? Give feedback.
-
yes please. I'd very much like to have the ability to just convert the hash into data from the server suitable to be used as img.src. please add support for it. 🙏 |
Beta Was this translation helpful? Give feedback.
-
I made my own decoder (no canvas or node-canvas required). https://gist.github.com/mattiaz9/53cb67040fa135cb395b1d015a200aff |
Beta Was this translation helpful? Give feedback.
-
In this case, you will need to use something like Closing. :) |
Beta Was this translation helpful? Give feedback.
-
Is there a way to decode it to data uri? like
data:image/png;base64,(decoded blurhash)
. So it'd be able to use on different platforms by returning that representation from my APIBeta Was this translation helpful? Give feedback.
All reactions