mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 22:26:57 +01:00
More caching for alpha-detecting avatars
This commit is contained in:
parent
9d2cc6942c
commit
ef874dd347
1 changed files with 2 additions and 1 deletions
|
@ -43,6 +43,7 @@ function Avatar({ url, size, alt = '', ...props }) {
|
||||||
}}
|
}}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
if (avatarRef.current) avatarRef.current.dataset.loaded = true;
|
if (avatarRef.current) avatarRef.current.dataset.loaded = true;
|
||||||
|
if (alphaCache[url] !== undefined) return;
|
||||||
try {
|
try {
|
||||||
// Check if image has alpha channel
|
// Check if image has alpha channel
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
|
@ -65,8 +66,8 @@ function Avatar({ url, size, alt = '', ...props }) {
|
||||||
if (hasAlpha) {
|
if (hasAlpha) {
|
||||||
// console.log('hasAlpha', hasAlpha, allPixels.data);
|
// console.log('hasAlpha', hasAlpha, allPixels.data);
|
||||||
avatarRef.current.classList.add('has-alpha');
|
avatarRef.current.classList.add('has-alpha');
|
||||||
alphaCache[url] = true;
|
|
||||||
}
|
}
|
||||||
|
alphaCache[url] = hasAlpha;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue