npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

batch-image-resizer

v0.0.8

Published

CLI tool for resizing and optimizing images.

Downloads

5

Readme

Batch image resizer

npm version dependencies devDependencies

CLI tool for resizing images using sharp and optimizing jpg and png files using imagemin. The CLI tool does not require imagemagick or graphicsmagick to be installed.

Supports both single files as well as recursive file finding and processing using a glob pattern.

Installation

$ npm install

Example

Using the -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]"

Flags

Default

-v, --version [print version number]
-h, --help [print help]

Required

-i, --input [example: -i ./input/example.png] [example: -i ./input] [required]
-o, --output [example: -o ./output/example.png] [example: -o ./output] [required]

Optional

-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]

Formats

<img
	alt="Example image description"
	srcset="example-500w.jpg 500w, example-1000w.jpg 1000w, example-1500w.jpg 1500w"
	src="example-1000w.jpg"
/>

<picture>
	<source srcset="example-500w.webp 500w, example-1000w.webp 1000w, example-1500w.webp 1500w" type="image/webp">
	<source srcset="example-500w.jpg 500w, example-1000w.jpg 1000w, example-1500w.jpg 1500w" type="image/jpeg">
	<img src="example-500w.jpg" alt="Example image description">
</picture>

Licence

My work is released under the MIT license.