i want to make the result of image manipulation to base64
so i can display it without store the image on my server
this is my code
const Jimp = require('jimp');
const base64 = require('node-base64-image');
var imgs = "https://scontent-sin6-1.cdninstagram.com/vp/86449fc9f74675290a52d4e2a133fdf9/5C0C1F53/t51.2885-15/e35/19436764_1153046358134464_2721742701283246080_n.jpg"
Jimp.read('frame.png',function (err,frame) {
base64.encode(imgs, {string: true}, function (err, image) {
if (err) {
console.log(err);
}
Jimp.read(Buffer.from(image.replace(/^data:image\/png;base64,/, ""), 'base64'),function (err,img) {
if (err) {
console.log(err);
}
let image_final = img
.resize(1000,1000)
.rotate(180)
.composite(frame,0,0)
.write('final_ig_180.jpg')
base64.encode(image_final, {string: true}, function (err, final_img) {
console.log(final_img);
})
})
})
})
but the result is undefined
just use the base64 function instead of write
Jimp.read(
'https://scontent-sin6-1.cdninstagram.com/vp/86449fc9f74675290a52d4e2a133fdf9/5C0C1F53/t51.2885-15/e35/19436764_1153046358134464_2721742701283246080_n.jpg'
).then(img => {
img.getBase64(Jimp.AUTO, (err, res) => {
console.log(res)
})
});
Most helpful comment
just use the
base64function instead ofwrite