Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.24 KB

README.md

File metadata and controls

60 lines (44 loc) · 1.24 KB

Resizer for srcset

A simple image resize with Node.js(using sharp) to generate the images in different sizes for use in srcset attribute in <img> tag.

Installation

Clone this repository:

git clone [email protected]:jucegt/resize-images-for-srcset.git resize-images

cd resize-images

How to use it?

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.

TODO:

  • Add the option to resize by percentage.
  • Do not resize if the sizes in the config file are larger than the original image size.
  • ???