Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Replacing a color in PNG files

I've found a library with PNG files for dungeon games at http://pousse.rapiere.free.fr/tome/.

But, the background of the tiles is not "transparent", it's "#ff00ff", or white.

How can I replace the colors easily with rgba(0,0,0,0) ? I could load the images into a HTML5 canvas and replace the colors there, but maybe there is a much easier way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Well, I've just found the replace-color function, and wrote a tool which updates all PNG file in a folder:

const fs = require('fs');
const path = require('path');
const replaceColor = require('replace-color');

function findPngFiles(dir) {
    var files = fs.readdirSync(dir);
    var pngFiles = [];
    for (let file of files) {
        file = path.join(dir, file);
        if (path.extname(file).toLowerCase() === '.png') {
            pngFiles.push(file);
        }
        if (fs.statSync(file).isDirectory()) {
            pngFiles = pngFiles.concat(findPngFiles(file));
        }
    }
    return pngFiles;
}

async function updateImage(file) {
    replaceColor({
        image: file,
        colors: {
            type: 'hex',
            targetColor: '#FF00FF',
            replaceColor: '#00000000'
        }
    })
        .then((jimpObject) => {
            jimpObject.write(file, (err) => {
                if (err) return console.log(err);
            });
        })
        .catch((err) => {
            console.log(err);
        });
}

const pngFiles = findPngFiles('./Items');

(async function updateFiles() {
    for(let file of pngFiles) {
        await updateImage(file);
        console.log(file);
    }
})()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!