sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Unable to apply mask image

Open kalitk0 opened this issue 10 months ago • 1 comments

I am unable to apply mask

Here is the mask file

Image

Here is the image that I am trying to apply mask to

Image

This is what I am trying to do

Process the mask file let processedMask = await sharp(maskBuffer).grayscale().resize(1288, 1288, { fit: 'fill' }).raw().toBuffer({ resolveWithObject: true });

This is how I try to apply the mask let maskedOverlay = await sharp(overlayPositioned, { raw: { width: 1288, height: 1288, channels: 4 } }).joinChannel(processedMask.data, { raw: processedMask.info }).raw().toBuffer();

I tried also with composite mode dest-in but it still does not apply the mask let maskedOverlay = await sharp(overlayPositioned, { raw: { width: 1288, height: 1288, channels: 4 } }).composite([{ input: processedMask.data, raw: processedMask.info, blend: 'dest-in' }]).raw().toBuffer();

What I am doing wrong, please help.

kalitk0 avatar Apr 21 '25 16:04 kalitk0

The input image appears to already have an alpha channel - are you trying to replace this with the mask? (The mask is currently a 3-channel RGB image - I guess you want this to be single-channel greyscale.)

lovell avatar Apr 23 '25 10:04 lovell

@kalitk0 Were you able to make any progress with this?

lovell avatar Sep 17 '25 13:09 lovell

Closing due to inactivity but please feel free to reopen with more details if further help is required.

lovell avatar Nov 04 '25 15:11 lovell