mirror of
https://github.com/lovell/sharp.git
synced 2026-02-10 16:46:14 +01:00
USAGE: overlayWith('overlayimage.png', { cutout: true } )
This commit is contained in:
committed by
Lovell Fuller
parent
f1ead06645
commit
2e9cd83ed2
@@ -45,6 +45,7 @@ using vips::VOption;
|
||||
using vips::VError;
|
||||
|
||||
using sharp::Composite;
|
||||
using sharp::Cutout;
|
||||
using sharp::Normalize;
|
||||
using sharp::Gamma;
|
||||
using sharp::Blur;
|
||||
@@ -464,8 +465,9 @@ class PipelineWorker : public AsyncWorker {
|
||||
bool shouldBlur = baton->blurSigma != 0.0;
|
||||
bool shouldSharpen = baton->sharpenSigma != 0.0;
|
||||
bool shouldThreshold = baton->threshold != 0;
|
||||
bool shouldCutout = baton->overlayCutout;
|
||||
bool shouldPremultiplyAlpha = HasAlpha(image) &&
|
||||
(shouldAffineTransform || shouldBlur || shouldSharpen || hasOverlay);
|
||||
(shouldAffineTransform || shouldBlur || shouldSharpen || (hasOverlay && !shouldCutout));
|
||||
|
||||
// Premultiply image alpha channel before all transformations to avoid
|
||||
// dark fringing around bright pixels
|
||||
@@ -699,10 +701,15 @@ class PipelineWorker : public AsyncWorker {
|
||||
// the overlayGravity was used for extract_area, therefore set it back to its default value of 0
|
||||
baton->overlayGravity = 0;
|
||||
}
|
||||
// Ensure overlay is premultiplied sRGB
|
||||
overlayImage = overlayImage.colourspace(VIPS_INTERPRETATION_sRGB).premultiply();
|
||||
// Composite images with given gravity
|
||||
image = Composite(overlayImage, image, baton->overlayGravity);
|
||||
if(shouldCutout) {
|
||||
// 'cut out' the image, premultiplication is not required
|
||||
image = Cutout(overlayImage, image, baton->overlayGravity);
|
||||
} else {
|
||||
// Ensure overlay is premultiplied sRGB
|
||||
overlayImage = overlayImage.colourspace(VIPS_INTERPRETATION_sRGB).premultiply();
|
||||
// Composite images with given gravity
|
||||
image = Composite(overlayImage, image, baton->overlayGravity);
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse premultiplication after all transformations:
|
||||
@@ -1086,6 +1093,7 @@ NAN_METHOD(pipeline) {
|
||||
}
|
||||
baton->overlayGravity = attrAs<int32_t>(options, "overlayGravity");
|
||||
baton->overlayTile = attrAs<bool>(options, "overlayTile");
|
||||
baton->overlayCutout = attrAs<bool>(options, "overlayCutout");
|
||||
// Resize options
|
||||
baton->withoutEnlargement = attrAs<bool>(options, "withoutEnlargement");
|
||||
baton->crop = attrAs<int32_t>(options, "crop");
|
||||
|
||||
Reference in New Issue
Block a user