Skip to content

Commit 367e7be

Browse files
authored
docs: update README (#12)
1 parent e66cdfe commit 367e7be

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ export default {
3030
};
3131
```
3232

33-
## Options
34-
35-
The plugin accepts an array of compressor configuration options, each of which can be either a string or an object. The string can be the name of a built-in compressor and its default configuration enabled.
36-
Or use the object format configuration and specify the compressor in the `use` field. The remaining fields of the object will be used as compressor configuration options.
33+
## Default Compressors
3734

3835
By default, the plugin will enable `jpeg`, `png`, `ico` image compressors, which are equivalent to the following two examples:
3936

@@ -45,19 +42,48 @@ pluginImageCompress(["jpeg", "png", "ico"]);
4542
pluginImageCompress([{ use: "jpeg" }, { use: "png" }, { use: "ico" }]);
4643
```
4744

45+
## Supported Compressors
46+
47+
The plugin supports the following compressors:
48+
49+
- `jpeg`: For JPEG images.
50+
- `png`: For PNG images.
51+
- `pngLossless`: For PNG images with lossless compression.
52+
- `ico`: For ICO images.
53+
- `svg`: For SVG images.
54+
- `avif`: For AVIF images.
55+
56+
Only SVG are compressed by `svgo`, other compressors are compressed by `@napi-rs/image`.
57+
58+
## Options
59+
60+
The plugin accepts an array of compressor configuration options, each of which can be either a string or an object. The string can be the name of a built-in compressor and its default configuration enabled.
61+
62+
Or use the object format configuration and specify the compressor in the `use` field. The remaining fields of the object will be used as compressor configuration options.
63+
4864
The default configuration can be overridden by specifying a configuration option.
4965
For example, to allow the jpeg compressor to recognize new extension name and to set the quality of the png compressor.
5066

5167
```js
5268
pluginImageCompress([
69+
// Options for @napi-rs/image `compressJpeg` method
5370
{ use: "jpeg", test: /\.(?:jpg|jpeg|jpe)$/ },
71+
// Options for @napi-rs/image `pngQuantize` method
5472
{ use: "png", minQuality: 50 },
55-
"ico",
73+
// Options for @napi-rs/image `avif` method
74+
{ use: "avif", quality: 80 },
75+
// Options for svgo
76+
{ use: 'svg', floatPrecision: 2 }
77+
// No options yet
78+
{ use: "ico" },
5679
]);
5780
```
5881

59-
The default `png` compressor is lossy.
60-
If you want to replace it with a lossless compressor, you can use the following configuration.
82+
For more information on compressors, please visit [@napi-rs/image](https://image.napi.rs/docs).
83+
84+
## Lossless PNG
85+
86+
The default `png` compressor is lossy. If you want to replace it with a lossless compressor, you can use the following configuration.
6187

6288
```js
6389
pluginImageCompress(["jpeg", "pngLossless", "ico"]);
@@ -71,8 +97,6 @@ For example, the `png` compressor will take precedence over the `pngLossless` co
7197
pluginImageCompress(["jpeg", "pngLossless", "ico", "png"]);
7298
```
7399

74-
For more information on compressors, please visit [@napi-rs/image](https://image.napi.rs/docs).
75-
76100
## License
77101

78102
[MIT](./LICENSE).

0 commit comments

Comments
 (0)