How to use the sharp.position function in sharp

To help you get started, we’ve selected a few sharp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vseventer / sharp-cli / lib / constants.js View on Github external
// Exports.
module.exports = {
  BAND: ['red', 'green', 'blue'],
  BLEND: Object.keys(sharp.blend),
  BOOL: Object.keys(sharp.bool),
  COLOURSPACE: Object.keys(sharp.colourspace),
  CONTAINER: ['fs', 'zip'],
  DEPTH: ['onepixel', 'onetile', 'one'],
  FIT: Object.keys(sharp.fit),
  FORMAT: ['heif', 'jpeg', 'jpg', 'png', 'raw', 'tiff', 'webp'],
  GRAVITY: Object.keys(sharp.gravity),
  HEIF_COMPRESSION: ['hevc', 'avc', 'jpeg', 'av1'],
  KERNEL: Object.keys(sharp.kernel),
  LAYOUT: ['dz', 'google', 'zoomify'],
  POSITION: Object.keys(sharp.position),
  STRATEGY: Object.keys(sharp.strategy),
  TIFF_COMPRESSION: ['ccittfax4', 'deflate', 'jpeg', 'lzw', 'none'],
  TIFF_PREDICTOR: ['float', 'horizontal', 'none']
}
github gridsome / gridsome / gridsome / lib / workers / image-processor.js View on Github external
jpegProgressive: true
    }

    const plugins = []
    let pipeline = sharp(buffer)

    if (
      (config.width && config.width <= width) ||
      (config.height && config.height <= height)
    ) {
      const resizeOptions = {}

      if (config.height) resizeOptions.height = config.height
      if (config.width) resizeOptions.width = config.width
      if (options.fit) resizeOptions.fit = sharp.fit[options.fit]
      if (options.position) resizeOptions.position = sharp.position[options.position]
      if (options.background && colorString.get(options.background)) {
        resizeOptions.background = options.background
      } else if (backgroundColor) {
        resizeOptions.background = backgroundColor
      }

      pipeline = pipeline.resize(resizeOptions)
    }

    if (/\.png$/.test(ext)) {
      const quality = config.quality / 100

      pipeline = pipeline.png({
        compressionLevel: config.pngCompressionLevel,
        adaptiveFiltering: false
      })
github gridsome / gridsome / gridsome / lib / app / queue / ImageProcessQueue.js View on Github external
async function createDataUri (buffer, type, width, height, defaultBlur, options = {}) {
  const blur = options.blur !== undefined ? parseInt(options.blur, 10) : defaultBlur

  const resizeOptions = {}

  if (options.fit) resizeOptions.fit = sharp.fit[options.fit]
  if (options.position) resizeOptions.position = sharp.position[options.position]
  if (options.background) resizeOptions.background = options.background

  const blurredSvg = await createBlurSvg(buffer, type, width, height, blur, resizeOptions)

  return svgDataUri(
    `<svg xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" fill="none">` +
    blurredSvg +
    `</svg>`
  )
}

sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images

Apache-2.0
Latest version published 4 months ago

Package Health Score

92 / 100
Full package analysis