Add ensureAlpha op, adds alpha channel if missing #1153

This commit is contained in:
Lovell Fuller
2019-01-05 21:12:33 +00:00
parent 8e70579e47
commit 4c01a099ea
9 changed files with 84 additions and 0 deletions

View File

@@ -29,6 +29,23 @@ function removeAlpha () {
return this;
}
/**
* Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
*
* @example
* sharp('rgb.jpg')
* .ensureAlpha()
* .toFile('rgba.png', function(err, info) {
* // rgba.png is a 4 channel image with a fully opaque alpha channel
* });
*
* @returns {Sharp}
*/
function ensureAlpha () {
this.options.ensureAlpha = true;
return this;
}
/**
* Extract a single channel from a multi-channel image.
*
@@ -120,6 +137,7 @@ module.exports = function (Sharp) {
Object.assign(Sharp.prototype, {
// Public instance functions
removeAlpha,
ensureAlpha,
extractChannel,
joinChannel,
bandbool

View File

@@ -144,6 +144,7 @@ const Sharp = function (input, options) {
joinChannelIn: [],
extractChannel: -1,
removeAlpha: false,
ensureAlpha: false,
colourspace: 'srgb',
// overlay
overlayGravity: 0,