Table of Contents


Overlay (composite) an image over the processed (resized, extracted etc.) image.

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


  • overlay (Buffer | String) Buffer containing image data or String containing the path to an image file.
  • options Object?
    • options.gravity String? gravity at which to place the overlay. (optional, default 'centre')
    • Number? the pixel offset from the top edge.
    • options.left Number? the pixel offset from the left edge.
    • options.tile Boolean? set to true to repeat the overlay image across the entire image with the given gravity. (optional, default false)
    • options.cutout Boolean? set to true to apply only the alpha channel of the overlay image to the input image, giving the appearance of one image being cut out of another. (optional, default false)
    • options.density Number? integral number representing the DPI for vector overlay image. (optional, default 72)
    • options.raw Object? describes overlay when using raw pixel data.
    • options.create Object? describes a blank overlay to be created.
      • options.create.width Number?
      • options.create.height Number?
      • options.create.channels Number? 3-4
      • options.create.background (String | Object)? parsed by the color module to extract values for red, green, blue and alpha.


  .overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
  .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 Invalid parameters

Returns Sharp