简体   繁体   中英

Create new image with transparent colour in jimp (js library) in Nodejs

I am using jimp to manipulate the image. Everything is working fine but when I am creating a new image with

new Jimp(256, 256, (err, image) => {
  // this image is 256 x 256, every pixel is set to 0x00000000
});

every pixel is set to 0x00000000

I need no background color image (it need to be transparent), How can I achieve this?

Edit : when I am sending a png image then it is giving me a transparent image, when the third argument is not passed when the third argument is not passed. And jpeg is giving me black. And I am also manipulating image before sending or showing

Thanks for help.

You should try this, as the last 2 digits of the color represent the alpha channel:

Or you can use a css color format:

new Jimp(256, 256, '#000000ff', (err, image) => {

});

As explained here:

https://www.npmjs.com/package/jimp#creating-new-images

透明度的十六进制颜色代码为0xFFFFFF00

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM