• input (Buffer | String)? if present, can be a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file. JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
  • options Object? if present, is an Object with optional attributes.
    • options.failOnError Boolean by default apply a "best effort" to decode images, even if the data is corrupt or invalid. Set this flag to true if you'd rather halt processing and raise an error when loading invalid images. (optional, default false)
    • options.density Number number representing the DPI for vector images. (optional, default 72)
    • Number page number to extract for multi-page input (GIF, TIFF) (optional, default 0)
    • options.raw Object? describes raw pixel input image data. See raw() for pixel ordering.
    • options.create Object? describes a new image 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.


  .resize(300, 200)
  .toFile('output.jpg', function(err) {
    // output.jpg is a 300 pixels wide and 200 pixels high image
    // containing a scaled and cropped version of input.jpg
// Read image data from readableStream,
// resize to 300 pixels wide,
// emit an 'info' event with calculated dimensions
// and finally write image data to writableStream
var transformer = sharp()
  .on('info', function(info) {
    console.log('Image height is ' + info.height);
// Create a blank 300x200 PNG image of semi-transluent red pixels
  create: {
    width: 300,
    height: 200,
    channels: 4,
    background: { r: 255, g: 0, b: 0, alpha: 0.5 }
.then( ... );
  • Throws Error Invalid parameters

Returns Sharp


An Object containing nested boolean values representing the available input and output formats/methods.



Returns Object


An Object containing the version numbers of libvips and its dependencies.




An EventEmitter that emits a change event when a task is either:

  • queued, waiting for libuv to provide a worker thread
  • complete


sharp.queue.on('change', function(queueLength) {
  console.log('Queue contains ' + queueLength + ' task(s)');