Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place image over an other image using Jimp

Tags:

node.js

npm

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.

image for seeing

I tried:

  • using only .png file
  • adding opacity to my images
  • using only images that have alpha canal
like image 526
Jeremy M. Avatar asked Mar 29 '18 12:03

Jeremy M.


People also ask

What is JIMP image?

JIMP, also known as JavaScript Image Manipulation Program, is an image processing library for Node written in JavaScript with no other dependency. It allows the user to easily manipulate the and transform the images into any required shape, format, dimnesion or style.

What is JIMP NPM?

Introduction. Jimp is a node module used to do image processing which is provided by the npm installer. The Jimp – Javascript Image Manipulation Program is a library written entirely in JavaScript for Node, without any external or native dependencies.


1 Answers

To make it work you have to use :

image.composite( src, x, y );     // composites another Jimp image over this image at x, y 

from jimp doc

because image.blit() is just deleting everything under your image.

like image 141
Jrmy Avatar answered Sep 20 '22 17:09

Jrmy