sharp-mozjpeg-image-processor
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

sharp-mozjpeg-image-processor

npm version Node Build & Test

Generates scaled (by sharp) and optimized (by mozjpeg) image files from a source image file

Install

$ npm i -save sharp-mozjpeg-image-processor

How to use

const fs = require('fs')
const { ImageProcessor } = require('sharp-mozjpeg-image-processor')

const processor = new ImageProcessor()

const srcStream = fs.createReadStream('./source.jpg')
const imgInfos = [
  {
    kind: 'large',
    width: 1200,
    height: 1200,
  },
  {
    kind: 'small',
    width: 800,
    height: 800,
  },
  {
    kind: 'thumb',
    width: 400,
    height: 400,
    crop: true, // cover for example thumbnail
  }
]
const quality = 70 // default 80 for jpeg image quality

processor.execute(srcStream, imgInfos, quality)
.then(outImgInfos => {
  for (let outImgInfo of outImgInfos) {
    console.log(outImgInfo)
  }
})
{
  kind: 'large',
  format: 'jpeg',
  width: 900,
  height: 1200,
  filePath: '/tmp/work897439499/optimized/large.jpg'
}
{
  kind: 'small',
  format: 'jpeg',
  width: 600,
  height: 800,
  filePath: '/tmp/work897439499/optimized/small.jpg'
}
{
  kind: 'thumb',
  format: 'jpeg',
  width: 400,
  height: 400,
  filePath: '/tmp/work897439499/optimized/thumb.jpg'
}

Readme

Keywords

Package Sidebar

Install

npm i sharp-mozjpeg-image-processor

Weekly Downloads

14

Version

0.6.0

License

MIT

Unpacked Size

9.93 kB

Total Files

7

Last publish

Collaborators

  • tilfin