Reputation: 1164
I'm trying to edit my images on my node.js application working on the server-side. At this moment, I've successfully added text over my image. I would like to place a green rectangle at the top left corner over this image and I tried this method:
Jimp.read(`borderTop.png`, function (err, top) {
top.rotate(45);
Jimp.read(`img.png`, function (err, image) {
if (err) console.log(err);
image.blit(top, 430, -250);
Jimp.loadFont(`${__dirname}/../public/fonts/*.fnt`).then(function (font) {
image.print(font, 315 - ((16 * 13 ) / 2), 0, "Hello, world!");
image.write(finalName, (err) => {
return cb(null, `img.png`);
});
});
});
});
This is working but it's removing part of my image that is under the border.
I tried:
.png
fileUpvotes: 18
Views: 21732
Reputation: 1
const { Jimp } = require9'jimp');
const textToImage = require('text-to-image');
let createdImage = textToImage.generate('text_Which_appear_on_image', {
bgColor: #ffffff00,
textColor: red,
fontSize: 20,
fontFamily: 'sans-serif',
lineHeight: 50,
customHeight: 200,
maxWidth: 350,
textAlign: 'center',
verticalAlign: 'center',
margin: 20
});
let jimpImage = Jimp.read(createdImage);
//now let say you have other image named baseImage
//so read them also
let baseImage = Jimp.read(baseImage);
//now composite them
const compositeImage = Jimp.composite(jimpImage, horizontal-alignment,
vertical-alignment,
Jimp.BLEND_SOURCE_OVER);
const finalImage = await compositeImage.getBufferAsync('image/png');
return finalImage;
Upvotes: 0
Reputation: 73
To combine a image on another image :
var Jimp = require('jimp');
Jimp.read('imageone.png', (err, fir_img) => {
if(err) {
console.log(err);
} else {
Jimp.read('imagetwo.png', (err, sec_img) => {
if(err) {
console.log(err);
} else {
fir_img.resize(600, 450);
fir_img.blit(sec_img, 0, 360);
fir_img.write('new_imgae.png');
}
})
}
});
Two images are complexed by jimp.blit().
Upvotes: 5