Canvas change image color

How to change image color, so i load an image of icon i need, and i have function that finds what icon through db. But main thing, the icon images are stored in folder in white color. I want to make multiple colors but then i have to save 100+ images in that folder. So, i need to somehow make it so canvas will change image color. Maybe by a shape and then blend it in image or something, i dont know. Code for function:
async function drawAchievementImage(ctx, achievementName, x, y, width, height) {
const imagePath = getAchievementImagePath(achievementName);
if (imagePath) {
try {
const achievementImage = await Canvas.loadImage(imagePath);
ctx.drawImage(achievementImage, x, y, width, height);
} catch (error) {
console.error(`Error loading image for ${achievementName}:`, error);
}
}
}
async function drawAchievementImage(ctx, achievementName, x, y, width, height) {
const imagePath = getAchievementImagePath(achievementName);
if (imagePath) {
try {
const achievementImage = await Canvas.loadImage(imagePath);
ctx.drawImage(achievementImage, x, y, width, height);
} catch (error) {
console.error(`Error loading image for ${achievementName}:`, error);
}
}
}
3 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
m1ntyx
m1ntyx2mo ago
so, how to change achievementImage to other colors? for example red, i will then add after height i will add color in function, but now show me how to change image color
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View