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

87
Views
How to edit base64 image in node js

I am trying to add one pixel to base64 picture. I want my express server to receive base64 image string (e.g. data:image/png;base64,iVBORw0KG...) for sake of example let's say that the image is 100x100px and I want to add red pixel on x=10 and y=10, and after that send it as response. I don't have any workable code to show because I don't know how to do it and can't find anything on internet. Express part is not an issue I know how to make that. Looking for any pointer in right direction, any recommendation or parts of code. Thank you!

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

0

You can use the Jimp package to do that.

Here is a simple example setting a red pixel on a 100x100 black png image:

const Jimp = require('jimp');
const { promisify } = require('util');

const MIME_TYPE = 'image/png';
const IMAGE_URL = `data:${MIME_TYPE};base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA0SURBVHhe7cEBDQAAAMKg909tDjcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAbNXWUAAEE/b5iAAAAAElFTkSuQmCC`;

const coords = {
    x: 10,
    y: 10
};

const color = {
    r: 255,
    g: 0,
    b: 0,
    a: 255
};

async function main(color, coords) {
    const imageData = IMAGE_URL.split(',').pop();
    const image = await Jimp.read(Buffer.from(imageData, 'base64'));

    const hexColor = Jimp.rgbaToInt(color.r, color.g, color.b, color.a);

    image.setPixelColor(hexColor, coords.x, coords.y);

    const toBase64 = promisify(image.getBase64).bind(image);

    return await toBase64(MIME_TYPE);
}

main(color, coords)
    .then(console.log)
    .catch(console.error);
about 4 years ago · Juan Pablo Isaza Report

0

Try using sharp to processes images. You can convert your base64 image into a buffer and use this library

var imgUri = base64Str.split(';base64,').pop()
var buffer = Buffer.from(uri, 'base64');
sharp(buffer)
 . // Do your thing here with sharp
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!