mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-16 23:31:19 +03:00
Make sure at least 10% has alpha
This commit is contained in:
parent
ba2e9c29e4
commit
eb4b22a265
1 changed files with 6 additions and 3 deletions
|
@ -56,9 +56,12 @@ function Avatar({ url, size, alt = '', ...props }) {
|
|||
canvas.width,
|
||||
canvas.height,
|
||||
);
|
||||
const hasAlpha = allPixels.data.some((pixel, i) => {
|
||||
return i % 4 === 3 && pixel <= 128;
|
||||
});
|
||||
// At least 10% of pixels have alpha <= 128
|
||||
const hasAlpha =
|
||||
allPixels.data.filter((pixel, i) => i % 4 === 3 && pixel <= 128)
|
||||
.length /
|
||||
(allPixels.data.length / 4) >
|
||||
0.1;
|
||||
if (hasAlpha) {
|
||||
// console.log('hasAlpha', hasAlpha, allPixels.data);
|
||||
avatarRef.current.classList.add('has-alpha');
|
||||
|
|
Loading…
Add table
Reference in a new issue