合成图像
composite
在已处理(调整大小,提取等)图像上的合成图像。
要合成的图像必须与处理后的图像相同或更小。如果同时提供top和left选项,则它们优先于gravity。
blend 选项可以是其中的一个:clear, source, over, in, out, atop, dest, dest-over, dest-in, dest-out, dest-atop, xor, add, saturate, multiply, screen, overlay, darken, lighten, colour-dodge, color-dodge, colour-burn,color-burn, hard-light, soft-light, difference, exclusion.
有关混合模式的更多信息,请参见 https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsBlendMode 和 https://www.cairographics.org/operators/
参数
imagesArray <Object > 要合成的图像的有序列表images[].input(Buffer | String )? 包含图像数据的缓冲区,包含图像文件路径的String或Create对象(请参见下文)images[].blendString 如何将此图像与下面的图像混合。(可选,默认'over')images[].gravityString 放置叠加层的位置。 (可选,默认'centre')images[].topNumber ? 距上边缘的像素偏移量。images[].leftNumber ? 距左边缘的像素偏移量。images[].tileBoolean 设置为true的可使用给定的gravity在整个图像上重复覆盖图像。(可选,默认为 false)images[].premultipliedBoolean 设置为true以避免预乘下图。等同于--premultipliedvips选项。(可选,默认为 false)images[].densityNumber 表示DPI为向量叠加图像数 (可选,默认72)images[].rawObject ? 描述使用原始像素数据时的覆盖。images[].animatedboolean 动画布尔值设置为true以读取动画图像的所有帧/页(可选,默认false)images[].failOnErrorboolean 请查看构造函数constructor parameters(可选,默认true)images[].limitInputPixels(number | boolean ) 请查看构造函数constructor parameters(可选,默认268402689)
例子
await sharp(background).composite([{ input: layer1, gravity: 'northwest' },{ input: layer2, gravity: 'southeast' },]).toFile('combined.png');
const output = await sharp('input.gif', { animated: true }).composite([{ input: 'overlay.png', tile: true, blend: 'saturate' }]).toBuffer();
sharp('input.png').rotate(180).resize(300).flatten( { background: '#ff6600' } ).composite([{ input: 'overlay.png', gravity: 'southeast' }]).sharpen().withMetadata().webp( { quality: 90 } ).toBuffer().then(function(outputBuffer) {// outputBuffer contains upside down, 300px wide, alpha channel flattened// onto orange background, composited with overlay.png with SE gravity,// sharpened, with metadata, 90% quality WebP image data. Phew!});
- 无效参数时抛出错误 Error
返回 Sharp 对象
Meta
- since: 0.22.0
