https://github.com/magicdawn/node-mozjpeg
mozjpeg node binding
https://github.com/magicdawn/node-mozjpeg
Last synced: 9 months ago
JSON representation
mozjpeg node binding
- Host: GitHub
- URL: https://github.com/magicdawn/node-mozjpeg
- Owner: magicdawn
- License: other
- Created: 2020-05-15T19:59:35.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-18T17:45:55.000Z (over 2 years ago)
- Last Synced: 2025-01-29T08:11:14.843Z (over 1 year ago)
- Language: C++
- Size: 10.2 MB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# node-mozjpeg
> mozjpeg node binding
[](https://travis-ci.org/magicdawn/node-mozjpeg)
[](https://codecov.io/gh/magicdawn/node-mozjpeg)
[](https://www.npmjs.com/package/node-mozjpeg)
[](https://www.npmjs.com/package/node-mozjpeg)
[](http://magicdawn.mit-license.org)
## Features
- [x] for a 10MB jpeg file, 2x fast than squoosh or @saschazar/wasm-mozjpeg wasm version.
- [x] None blocking mozjpeg compress. (u should wrap wasm version it in a WebWorker or node.js Worker)
## Install
```sh
$ npm i -S node-mozjpeg
```
## API
```js
const mozjpeg = require('node-mozjpeg')
```
### types
```ts
export const version: string
export enum ColorSpace {
GRAYSCALE = 1,
RGB,
YCbCr,
}
export interface EncodeOptions {
quality: number
baseline: boolean
arithmetic: boolean
progressive: boolean
optimize_coding: boolean
smoothing: number
color_space: ColorSpace
quant_table: number
trellis_multipass: boolean
trellis_opt_zero: boolean
trellis_opt_table: boolean
trellis_loops: number
auto_subsample: boolean
chroma_subsample: number
separate_chroma_quality: boolean
chroma_quality: number
}
```
### encodeSync
this will **block** the EventLoop, **do not** use in production
```ts
export function encodeSync(
input: Buffer,
width: number,
height: number,
options?: Partial
): Buffer
```
### encode
same as `encodeSync` except it's using libuv to encode and return Promise
```ts
export function encode(
input: Buffer,
width: number,
height: number,
options?: Partial
): Promise
```
### defaultOptions
```js
const defaultOptions = {
quality: 75,
baseline: false,
arithmetic: false,
progressive: true,
optimize_coding: true,
smoothing: 0,
color_space: ColorSpace.YCbCr,
quant_table: 3,
trellis_multipass: false,
trellis_opt_zero: false,
trellis_opt_table: false,
trellis_loops: 1,
auto_subsample: true,
chroma_subsample: 2,
separate_chroma_quality: false,
chroma_quality: 75,
}
```
## Changelog
[CHANGELOG.md](CHANGELOG.md)
## License
the MIT License [LICENSE](LICENSE)