Add unflatten operation to create an alpha channel (#3461)

This commit is contained in:
Anton Marsden
2023-04-07 22:01:29 +12:00
committed by GitHub
parent b9c3851515
commit a4c6eba7d4
11 changed files with 93 additions and 0 deletions

View File

@@ -405,6 +405,25 @@ function flatten (options) {
return this;
}
/**
* Unflatten - add an alpha channel to the image if required, and make white pixels fully transparent. Alpha for non-white pixels will be unchanged/opaque.
*
* @example
* await sharp(rgbInput)
* .unflatten()
* .toBuffer();
*
* @example
* await sharp(rgbInput)
* .threshold(128, { grayscale: false }) // converter bright pixels to white
* .unflatten()
* .toBuffer();
*/
function unflatten (options) {
this.options.unflatten = is.bool(options) ? options : true;
return this;
}
/**
* Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma`
* then increasing the encoding (brighten) post-resize at a factor of `gamma`.
@@ -875,6 +894,7 @@ module.exports = function (Sharp) {
median,
blur,
flatten,
unflatten,
gamma,
negate,
normalise,