mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Add unflatten operation to create an alpha channel (#3461)
This commit is contained in:
@@ -217,6 +217,7 @@ const Sharp = function (input, options) {
|
||||
tintB: 128,
|
||||
flatten: false,
|
||||
flattenBackground: [0, 0, 0],
|
||||
unflatten: false,
|
||||
negate: false,
|
||||
negateAlpha: true,
|
||||
medianSize: 0,
|
||||
|
||||
7
lib/index.d.ts
vendored
7
lib/index.d.ts
vendored
@@ -427,6 +427,13 @@ declare namespace sharp {
|
||||
*/
|
||||
flatten(flatten?: boolean | FlattenOptions): Sharp;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param unflatten true to enable and false to disable (defaults to true)
|
||||
* @returns A sharp instance that can be used to chain operations
|
||||
*/
|
||||
unflatten(unflatten?: boolean): Sharp;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user