https://github.com/tilfin/sharp-mozjpeg-image-processor
Scaled and optimized JPEG image file generater powered by sharp and mozjpeg
https://github.com/tilfin/sharp-mozjpeg-image-processor
image-processing mozjpeg sharp
Last synced: 7 months ago
JSON representation
Scaled and optimized JPEG image file generater powered by sharp and mozjpeg
- Host: GitHub
- URL: https://github.com/tilfin/sharp-mozjpeg-image-processor
- Owner: tilfin
- License: mit
- Created: 2020-02-06T04:25:28.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-17T11:41:34.000Z (9 months ago)
- Last Synced: 2025-02-05T14:12:33.741Z (8 months ago)
- Topics: image-processing, mozjpeg, sharp
- Language: TypeScript
- Homepage:
- Size: 459 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sharp-mozjpeg-image-processor
[](https://npmjs.org/package/sharp-mozjpeg-image-processor)
[]()
[](https://github.com/tilfin/sharp-mozjpeg-image-processor/actions/workflows/ci.yml)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
```js
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 qualityprocessor.execute(srcStream, imgInfos, quality)
.then(outImgInfos => {
for (let outImgInfo of outImgInfos) {
console.log(outImgInfo)
}
})
``````js
{
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'
}
```