<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## composite

Composite image(s) over the processed (resized, extracted etc.) image.

The images to composite must be the same size or smaller than the processed image.
If both `top` and `left` options are provided, they take precedence over `gravity`.

Any resize or rotate operations in the same processing pipeline
will always be applied to the input image before composition.

The `blend` option can be one of `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`.

More information about blend modes can be found at
[https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode][1]
and [https://www.cairographics.org/operators/][2]

### Parameters

*   `images` **[Array][3]<[Object][4]>** Ordered list of images to composite

    *   `images[].input` **([Buffer][5] | [String][6])?** Buffer containing image data, String containing the path to an image file, or Create object (see below)

        *   `images[].input.create` **[Object][4]?** describes a blank overlay to be created.

            *   `images[].input.create.width` **[Number][7]?**&#x20;
            *   `images[].input.create.height` **[Number][7]?**&#x20;
            *   `images[].input.create.channels` **[Number][7]?** 3-4
            *   `images[].input.create.background` **([String][6] | [Object][4])?** parsed by the [color][8] module to extract values for red, green, blue and alpha.
        *   `images[].input.text` **[Object][4]?** describes a new text image to be created.

            *   `images[].input.text.text` **[string][6]?** text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
            *   `images[].input.text.font` **[string][6]?** font name to render with.
            *   `images[].input.text.fontfile` **[string][6]?** absolute filesystem path to a font file that can be used by `font`.
            *   `images[].input.text.width` **[number][7]** integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. (optional, default `0`)
            *   `images[].input.text.height` **[number][7]** integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. (optional, default `0`)
            *   `images[].input.text.align` **[string][6]** text alignment (`'left'`, `'centre'`, `'center'`, `'right'`). (optional, default `'left'`)
            *   `images[].input.text.justify` **[boolean][9]** set this to true to apply justification to the text. (optional, default `false`)
            *   `images[].input.text.dpi` **[number][7]** the resolution (size) at which to render the text. Does not take effect if `height` is specified. (optional, default `72`)
            *   `images[].input.text.rgba` **[boolean][9]** set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. (optional, default `false`)
            *   `images[].input.text.spacing` **[number][7]** text line height in points. Will use the font line height if none is specified. (optional, default `0`)
    *   `images[].blend` **[String][6]** how to blend this image with the image below. (optional, default `'over'`)
    *   `images[].gravity` **[String][6]** gravity at which to place the overlay. (optional, default `'centre'`)
    *   `images[].top` **[Number][7]?** the pixel offset from the top edge.
    *   `images[].left` **[Number][7]?** the pixel offset from the left edge.
    *   `images[].tile` **[Boolean][9]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
    *   `images[].premultiplied` **[Boolean][9]** set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option. (optional, default `false`)
    *   `images[].density` **[Number][7]** number representing the DPI for vector overlay image. (optional, default `72`)
    *   `images[].raw` **[Object][4]?** describes overlay when using raw pixel data.

        *   `images[].raw.width` **[Number][7]?**&#x20;
        *   `images[].raw.height` **[Number][7]?**&#x20;
        *   `images[].raw.channels` **[Number][7]?**&#x20;
    *   `images[].animated` **[boolean][9]** Set to `true` to read all frames/pages of an animated image. (optional, default `false`)
    *   `images[].failOn` **[string][6]** @see [constructor parameters][10] (optional, default `'warning'`)
    *   `images[].limitInputPixels` **([number][7] | [boolean][9])** @see [constructor parameters][10] (optional, default `268402689`)

### Examples

```javascript
await sharp(background)
  .composite([
    { input: layer1, gravity: 'northwest' },
    { input: layer2, gravity: 'southeast' },
  ])
  .toFile('combined.png');
```

```javascript
const output = await sharp('input.gif', { animated: true })
  .composite([
    { input: 'overlay.png', tile: true, blend: 'saturate' }
  ])
  .toBuffer();
```

```javascript
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!
  });
```

*   Throws **[Error][11]** Invalid parameters

Returns **Sharp**&#x20;

**Meta**

*   **since**: 0.22.0

[1]: https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode

[2]: https://www.cairographics.org/operators/

[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[5]: https://nodejs.org/api/buffer.html

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[8]: https://www.npmjs.org/package/color

[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[10]: /api-constructor#parameters

[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
