Batch image resizer
Supports both single files as well as recursive file finding and processing using a glob pattern.
$ npm install
-s flag followed by an array of numbers one can specify (in pixels) the image sizes one wants to resize their image(s) to.
The input flag
-i takes either a single parent directory or a single file. The script will recursivly find a copy all suitable input files in all child directories. The folder structure of the input folder is retained in the output folder. Please note that this does not happen in-place but rather in the output directory.
Running the following command turns
$ node ./bin/batch-image-resizer.js -i ./input -o ./output -s "[50, 500, 1000, 1500]"
This as input (root with a single image, a parent folder which has a single image and a child folder of the parent which contains a single image).
root├── example-1.jpg└── parent├── child│ └── example-3.jpg└── example-2.jpg
Will in turn generate this as output (root with single image converted in various formats, a parent folder which contains a single image converted in various formats and a child folder of the parent which contains a single image converted in various formats).
root├── example-1-1000w.jpg├── example-1-1500w.jpg├── example-1-500w.jpg├── example-1-50w.jpg└── parent├── child│ ├── example-3-1000w.jpg│ ├── example-3-1500w.jpg│ ├── example-3-500w.jpg│ └── example-3-50w.jpg├── example-2-1000w.jpg├── example-2-1500w.jpg├── example-2-500w.jpg└── example-2-50w.jpg
Alternatively one could specify a single file as input rather than a directory.
$ node ./bin/batch-image-resizer.js -i ./input/example.png -o ./output/example.png -s "[50, 500, 1000, 1500]"
-v, --version [print version number] -h, --help [print help]
-i, --input [example: -i ./input/example.png] [example: -i ./input] [required] -o, --output [example: -o ./output/example.png] [example: -o ./output] [required]
-s, --sizes [example: -s "[50, 500, 1000, 1500]"] [not required] -f, --fit [fit to largest dimension, either width or height] [not required] -k, --keep-name [do not rename files] [not required]
My work is released under the MIT license.