lib/output.js
function png (options) {
  if (is.object(options)) {
    if (is.defined(options.progressive)) {
      this._setBooleanOption('pngProgressive', options.progressive);
    }
    if (is.defined(options.compressionLevel)) {
      if (is.integer(options.compressionLevel) && is.inRange(options.compressionLevel, 0, 9)) {
        this.options.pngCompressionLevel = options.compressionLevel;
      } else {
        throw new Error('Invalid compressionLevel (integer, 0-9) ' + options.compressionLevel);
      }
    }
    if (is.defined(options.adaptiveFiltering)) {
      this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
    }
    if (is.defined(options.palette)) {
      this._setBooleanOption('pngPalette', options.palette);
      if (this.options.pngPalette) {
        if (is.defined(options.quality)) {
          if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
            this.options.pngQuality = options.quality;
          } else {
            throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
          }
        }
        const colours = options.colours || options.colors;
        if (is.defined(colours)) {
          if (is.integer(colours) && is.inRange(colours, 2, 256)) {
            this.options.pngColours = colours;
          } else {
            throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
          }
        }
        if (is.defined(options.dither)) {
          if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
            this.options.pngDither = options.dither;
          } else {
            throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
          }
        }
      }
    }
  }
  return this._updateFormatOut('png', options);
}
function png (options) {
  if (is.object(options)) {
    if (is.defined(options.progressive)) {
      this._setBooleanOption('pngProgressive', options.progressive);
    }
    if (is.defined(options.compressionLevel)) {
      if (is.integer(options.compressionLevel) && is.inRange(options.compressionLevel, 0, 9)) {
        this.options.pngCompressionLevel = options.compressionLevel;
      } else {
        throw new Error('Invalid compressionLevel (integer, 0-9) ' + options.compressionLevel);
      }
    }
    if (is.defined(options.adaptiveFiltering)) {
      this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
    }
    if (is.defined(options.palette)) {
      this._setBooleanOption('pngPalette', options.palette);
      if (this.options.pngPalette) {
        if (is.defined(options.quality)) {
          if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
            this.options.pngQuality = options.quality;
          } else {
            throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
          }
        }
        const colours = options.colours || options.colors;
        if (is.defined(colours)) {
          if (is.integer(colours) && is.inRange(colours, 2, 256)) {
            this.options.pngColours = colours;
          } else {
            throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
          }
        }
        if (is.defined(options.dither)) {
          if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
            this.options.pngDither = options.dither;
          } else {
            throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
          }
        }
      }
    }
  }
  return this._updateFormatOut('png', options);
}
function png ( options ) { if ( is . object ( options ) ) { if ( is . defined ( options . progressive ) ) { this . _setBooleanOption ( 'pngProgressive' , options . progressive ) ; } if ( is . defined ( options . compressionLevel ) ) { if ( is . integer ( options . compressionLevel ) && is . inRange ( options . compressionLevel , 0 , 9 ) ) { this . options . pngCompressionLevel = options . compressionLevel ; } else { throw new Error ( 'Invalid compressionLevel (integer, 0-9) ' + options . compressionLevel ) ; } } if ( is . defined ( options . adaptiveFiltering ) ) { this . _setBooleanOption ( 'pngAdaptiveFiltering' , options . adaptiveFiltering ) ; } if ( is . defined ( options . palette ) ) { this . _setBooleanOption ( 'pngPalette' , options . palette ) ; if ( this . options . pngPalette ) { if ( is . defined ( options . quality ) ) { if ( is . integer ( options . quality ) && is . inRange ( options . quality , 0 , 100 ) ) { this . options . pngQuality = options . quality ; } else { throw is . invalidParameterError ( 'quality' , 'integer between 0 and 100' , options . quality ) ; } } const colours = options . colours || options . colors ; if ( is . defined ( colours ) ) { if ( is . integer ( colours ) && is . inRange ( colours , 2 , 256 ) ) { this . options . pngColours = colours ; } else { throw is . invalidParameterError ( 'colours' , 'integer between 2 and 256' , colours ) ; } } if ( is . defined ( options . dither ) ) { if ( is . number ( options . dither ) && is . inRange ( options . dither , 0 , 1 ) ) { this . options . pngDither = options . dither ; } else { throw is . invalidParameterError ( 'dither' , 'number between 0.0 and 1.0' , options . dither ) ; } } } } } return this . _updateFormatOut ( 'png' , options ) ; }
Use these PNG options for output image.

PNG output is always full colour at 8 or 16 bits per pixel.
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.

@example
// Convert any input to PNG output
const data = await sharp(input)
.png()
.toBuffer();

@param {Object} [options]
@param {Boolean} [options.progressive=false] - use progressive (interlace) scan
@param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
@param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
@param {Boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
@param {Number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, requires libvips compiled with support for libimagequant
@param {Number} [options.colours=256] - maximum number of palette entries, requires libvips compiled with support for libimagequant
@param {Number} [options.colors=256] - alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant
@param {Number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant
@param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
@returns {Sharp}
@throws {Error} Invalid options
Use these PNG options for output image .