Re-exports Sharp directly. All options and defaults are Sharp's own.
npm i @nodedk/image
var image = require('@nodedk/image')
The following examples run inside an async function.
var metadata = await image('photo.jpg').metadata()
console.log(metadata.width, metadata.height, metadata.format)
A Buffer can be passed instead of a file path.
await image('photo.jpg')
.resize({ width: 1200, withoutEnlargement: true })
.webp({ quality: 85 })
.toFile('photo.webp')
var output = await image(buffer)
.webp({ quality: 85 })
.toBuffer()
var photo = image(buffer)
var { width } = await photo.metadata()
await photo
.resize({ width: Math.max(1, Math.round(width / 2)) })
.webp({ quality: 85 })
.toFile('photo.webp')
var fs = require('node:fs')
var { pipeline } = require('node:stream/promises')
await pipeline(
fs.createReadStream('photo.jpg'),
image().webp({ quality: 85 }),
fs.createWriteStream('photo.webp')
)
For advanced usage, see the Sharp repository and API documentation.
Created by Vidar Eldøy