Add blurhash user background for Most Active Users card

This commit is contained in:
JonnyWong16 2021-03-19 11:10:30 -07:00
parent b19b9a70be
commit 74d6b18b47
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
4 changed files with 44 additions and 3 deletions

View file

@ -872,4 +872,40 @@ function short_season(title) {
return 'S' + title.substring(7)
}
return title
}
}
function loadAllBlurHash() {
$('[data-blurhash]').each(function() {
const elem = $(this);
const src = elem.data('blurhash');
loadBlurHash(elem, src);
});
}
function loadBlurHash(elem, src) {
const img = new Image();
img.src = src;
img.onload = () => {
const imgData = blurhash.getImageData(img);
blurhash
.encodePromise(imgData, img.width, img.height, 4, 4)
.then(hash => {
return blurhash.decodePromise(
hash,
img.width,
img.height
);
})
.then(blurhashImgData => {
const imgObject = blurhash.getImageDataAsImage(
blurhashImgData,
img.width,
img.height,
(event, imgObject) => {
elem.css('background-image', 'url(' + imgObject.src + ')')
}
);
});
}
}