Add alpha channels, if missing, to overlayWith images (#540)

This commit is contained in:
cmtt
2016-08-13 18:19:15 +02:00
committed by Lovell Fuller
parent 82ec2715f1
commit fc2002fbd0
3 changed files with 28 additions and 4 deletions

View File

@@ -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) {