working on a project
document.querySelectorAll('img').forEach(img => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const pixels = ctx.getImageData(0, 0, img.width, img.height).data;
let targetColorCount = 0;
const targetRGB = [104, 152, 76]; // #68984c in RGB
for (let i = 0; i < pixels.length; i += 4) {
const r = pixels[i], g = pixels[i+1], b = pixels[i+2];
if (Math.abs(r - targetRGB[0]) < 20 && Math.abs(g - targetRGB[1]) < 20 && Math.abs(b - targetRGB[2]) < 20) {
targetColorCount++;
}
}
if (targetColorCount / (pixels.length / 4) > 0.4) {
img.style.display = 'none';
}
});
document.querySelectorAll('img').forEach(img => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const pixels = ctx.getImageData(0, 0, img.width, img.height).data;
let targetColorCount = 0;
const targetRGB = [104, 152, 76]; // #68984c in RGB
for (let i = 0; i < pixels.length; i += 4) {
const r = pixels[i], g = pixels[i+1], b = pixels[i+2];
if (Math.abs(r - targetRGB[0]) < 20 && Math.abs(g - targetRGB[1]) < 20 && Math.abs(b - targetRGB[2]) < 20) {
targetColorCount++;
}
}
if (targetColorCount / (pixels.length / 4) > 0.4) {
img.style.display = 'none';
}
});