mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add alpha channels, if missing, to overlayWith images (#540)
This commit is contained in:
@@ -581,6 +581,20 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
// 'cut out' the image, premultiplication is not required
|
||||
image = sharp::Cutout(overlayImage, image, baton->overlayGravity);
|
||||
} else {
|
||||
// Ensure overlay has alpha channel
|
||||
if (!HasAlpha(overlayImage)) {
|
||||
double const multiplier = sharp::Is16Bit(overlayImage.interpretation()) ? 256.0 : 1.0;
|
||||
overlayImage = overlayImage.bandjoin(
|
||||
VImage::new_matrix(overlayImage.width(), overlayImage.height()).new_from_image(255 * multiplier)
|
||||
);
|
||||
}
|
||||
// Ensure image has alpha channel
|
||||
if (!HasAlpha(image)) {
|
||||
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
||||
image = image.bandjoin(
|
||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier)
|
||||
);
|
||||
}
|
||||
// Ensure overlay is premultiplied sRGB
|
||||
overlayImage = overlayImage.colourspace(VIPS_INTERPRETATION_sRGB).premultiply();
|
||||
if (baton->overlayXOffset >= 0 && baton->overlayYOffset >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user