Once you have the code, follow these steps to get started:
- Install the dependencies:
npm install - Create a parameter file:
npm run init-params - Edit the parameter file to set the parameters for your optimization.
- Place the images you want to optimize in directory specified in the parameters.
- Run the report:
npm run optimize
There are several parameters that can be set in the params.json file. The parameters are:
| Name | Type |
|---|---|
| input | Object |
| output | Object |
| resize | Object |
| compress | Object |
The input parameter is an Object for specifying options for the input images. For example:
"input": {
dir: "./input-images",
}| Name | Type | Description |
|---|---|---|
| dir | string |
The path to the desired input directory. Accepts any subdirectory structure. |
The output parameter is an Object for specifying options for the output (optimized) images. For example:
"output": {
dir: "./output-images",
}| Name | Type | Description |
|---|---|---|
| dir | string |
The path to the desired output directory. Accepts any subdirectory structure. |
The resize parameter is an Object for specifying options for resizing the images. For example:
resize: {
enabled: false,
sizes: [600, 900, 1200, 2400],
},| Name | Type | Description |
|---|---|---|
| enabled | boolean |
Whether or not to resize the images. |
| sizes | number[] |
The sizes to resize the images to. Accepts any number of sizes. |
The compress parameter is an Object for specifying options for compressing the images. For example:
compress: {
quality: 65,
},| Name | Type | Description |
|---|---|---|
| quality | number |
The quality of the compressed images. Accepts any number between 0 and 100. |