Sharp: Mask image

Created on 16 Feb 2018  路  2Comments  路  Source: lovell/sharp

Hi,
sorry for the noob quertion but i've looked around and i didn't found what i'm looking for.
i want to mask an A image with a b image transforming image b's pixels to transparent pixel and leaving imageb's white pixels as is...
in this Case A+C = C where C is an image with the same size of A and B but with alpha where not white

Example Image

Thanks in advance and sorry for my english

question

Most helpful comment

Hi, i tried with a wrong png and it didn't worked, so i've posted the question. Using another png file it worked like a charm.
var mask = 'mask_test_2.png'; sharp('mask_test_1.png').overlayWith(mask,{ cutout : true }).toFile('prova.png');

All 2 comments

Hello, did you see the cutout option of overlayWith?

The third example in the README uses this.

Hi, i tried with a wrong png and it didn't worked, so i've posted the question. Using another png file it worked like a charm.
var mask = 'mask_test_2.png'; sharp('mask_test_1.png').overlayWith(mask,{ cutout : true }).toFile('prova.png');

Was this page helpful?
0 / 5 - 0 ratings