A simple image resize with Node.js(using sharp) to generate the images in different sizes for use in srcset attribute in <img>
tag.
Clone this repository:
git clone [email protected]:jucegt/resize-images-for-srcset.git resize-images
cd resize-images
Create a folder in the root of the project and inside it place the images to resize(by default, it is called src
in the config file). In the config file you can change the input and output folder of the images.
{
"input": "./src/",
"output": "./dist/",
...
}
In the config file change or add sizes and formats to generate the images.
{
...
"sizes": [
{
"name": "lg",
"width": 800,
"height": 300
}
],
"formats": ["webp"]
}
To avoid generating extra formats, leave the formats
parameter as an empty array.
{
...
"formats": []
}
Use yarn images
or npm images
to generate the images.
PS. Don't forget to install the necessary modules using yarn install
or npm install
.
- Add the option to resize by percentage.
- Do not resize if the sizes in the config file are larger than the original image size.
- ???