Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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']
}
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
})
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>`
)
}