// Paints a photo's blurhash onto the <canvas> it's set on, as the
// placeholder shown until the image above it has loaded
// (CartosnapAppWeb.PhotoComponents.photo_image).
import {decode, isBlurhashValid} from "blurhash"
const SIZE = 32
export default {
mounted() { this.paint() },
updated() { this.paint() },
paint() {
const hash = this.el.dataset.hash
if (!hash || hash === this.painted || !isBlurhashValid(hash).result) return
const pixels = decode(hash, SIZE, SIZE)
const ctx = this.el.getContext("2d")
const image = ctx.createImageData(SIZE, SIZE)
image.data.set(pixels)
ctx.putImageData(image, 0, 0)
this.painted = hash
}
}
neiam
/cartosnap_ex
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
675 B · text
History
44bc4f7