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

image-down

v0.1.0

Published

Yet another library / CLI tool to batch compress / downscale images.

Downloads

9

Readme

image-down

npm license size GitHub release

Yet another CLI tool to batch compress / downscale images.

:green_book: Quick Start

npx image-down images/* --width 800 --output compressed
import { compressImages } from 'image-down';

// Wildcards are not supported in library usages
await compressImages(['./images/image1.jpg'], {
  width: 800,
  outputDir: 'compressed',
});

:wrench: Cli

Usage: npx image-down [options]

Commands:
  help     Display help
  version  Display version

Options:
  -f, --format      Convert images to a format.
  -h, --height      Resize images to a certain height.
  -H, --help        Output usage information
  -o, --output      Specify the output directory, default to '.'.
  -p, --percentage  Resize images according to the width by percentage.
  -s, --suffix      Adding a suffix to the output filename.
  -v, --version     Output the version number
  -w, --width       Resize images to a certain width.

Examples:
  - Compressing all files from folder images to jpg with widths of 800px and add '-min' to converted filenames, saving all compressed images to folder compressed.
  $ npx image-down images/* --width 800 --format jpg --suffix min --output compressed

:book: Library

await compressImages(pathsArray, options);

Options

| Name | Type | Description | | -------------------- | -------- | -------------------------------------------------------------- | | percentage | number | Resize images according to the width by percentage. | | width | number | Resize images to a certain width. | | height | number | Resize images to a certain height. | | format | number | Convert images to a format. | | outputDir | string | Specify the output directory, will not output if not defined. | | outputFilenameSuffix | string | Adding a suffix to the output filename. | | returnBuffers | boolean | Returning all converted buffers with corresponding file paths. | | onProgress | Function | A function that is called when each file is processed. |

onProgress

| Name | Type | Description | | ------------------- | ------ | ------------------------------ | | filePath | string | The original path to the file. | | fileBuffer | Buffer | The converted file buffer. | | progress | Object | The progress object. | | progress.queueIndex | number | File index. | | progress.total | number | Queue length. | | progress.status | string | "success" or "failed. | | progress.filename | string | The name of the output file. |

Completed Example

/**
 * Compressing all files from folder images to jpg with widths of 800px
 * and add '-min' to converted filenames,
 * saving all compressed images to folder compressed.
 */

import { glob } from 'glob';
import { compressImages } from 'image-down';

const filePaths = await glob('images/*');
await compressImages(filePaths, {
  width: 800,
  format: 'jpg',
  suffix: 'min',
  output: './compressed',
  onProgress({ progress }) {
    console.log(`Saved ${progress.filename}.`);
  },
});