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

images-folder-optimizer

v0.0.37

Published

A high performance package that uses sharp.js to recursively optimize, transform and convert images from a folder to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images. It is also possible to add watermark to the output images controlling opacity

Downloads

8

Readme

images-folder-optimizer

A high performance package that uses sharp.js to recursively optimize, transform and convert images from a folder to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images. It is also possible to add watermark to the output images controlling opacity and positioning.

GITHUB VERSION NPM VERSION NPM Downloads NPM License Twitter

FEATURES

  • PROCCESS ALL IMAGE FILES IN A FOLDER AT ONCE
  • SIGNIFICANT REDUCTION IN IMAGE SIZE
  • SCAN FOR IMAGE FILES RECURSIVELY ON ALL SUBFOLDERS
  • CONVERSION BETWEEN IMAGE FORMATS, CHOOSING BOTH INPUT AND OUTPUT FORMATS
  • IMAGE RESIZING
  • IMAGE TRANSFORMATIONS (ONLY BLUR FOR NOW)
  • POSSIBILITY TO OVERLAP A WATERMARK IMAGE CONTROLLING ITS OPACITY
  • FULL TYPESCRIPT SUPPORT
  • FULL CONTROL FOR SHARP.JS PARAMETERS

HOW TO USE IN YOUR PROJECT

  • INSTALL THE PACKAGE:

    npm install -D images-folder-optimizer
  • CREATE A JAVASCRIPT (OR TYPESCRIPT) FILE, AS example.js:

    import { functionOptimizeImages } from 'images-folder-optimizer';
    
    functionOptimizeImages({
        stringOriginFolder: 'static/images/originals',
        stringDestinationFolder: 'static/images/optimized',
        arrayOriginFormats: ['jpg', 'png'],
        arrayDestinationFormats: ['webp', 'avif'],
    }).then((results) => {
        console.table(results);
    });
  • RUN THE FILE:

    node example.js
  • CHECK THE NEW IMAGES IN static/images/optimized.

BUILT-IN EXAMPLES

YOU CAN FIND BUILT-IN EXAMPLES IN src/examples/ [LINK]. LET'S TRY ONE OF THEM:

npx tsc
node dist/examples/exampleFormatConversion.js

PARAMETERS AND TYPING

  • PARAMETERS FOR functionOptimizeImages:

| PARAMETER | DESCRIPTION | TYPE | REQUIRED | DEFAULT | | - | - | - | - | - | | stringOriginFolder | THE FOLDER WITH THE ORIGINAL IMAGES | string | YES | - | | stringDestinationFolder | THE FOLDER WHERE THE OPTIMIZED IMAGES ARE GOING TO BE SAVED | string | YES | - | | arrayOriginFormats | FORMATS OF THE ORIGINAL IMAGES | ARRAY WITH ELEMENTS BEEING 'webp' OR 'avif' OR 'png' OR 'jpg' OR 'tiff' OR 'gif' | YES | - | | arrayDestinationFormats | FORMATS FOR THE NEW IMAGES | ARRAY WITH ELEMENTS BEEING 'webp' OR 'avif' OR 'png' OR 'jpg' OR 'tiff' OR 'gif' OR 'svg' | YES | - | | stringFileNameSuffix | SUFIX FOR THE NEW FILE NAMES. EVERY ORIGINAL FILE NAME WITH THIS SUFIX IS GOING TO BE IGNORED | NO | - | | objectResizeOptions | SHARP.JS OPTIONS FOR IMAGE RESIZING | CHECK IT HERE | NO | - | | objectPngOptions | SHARP.JS OPTIONS FOR PNG TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectJpegOptions | SHARP.JS OPTIONS FOR JPG TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectWebpOptions | SHARP.JS OPTIONS FOR WEBP TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectAvifOptions | SHARP.JS OPTIONS FOR AVIF TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectAvifOptions | SHARP.JS OPTIONS FOR AVIF TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectTiffOptions | SHARP.JS OPTIONS FOR TIFF TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectGifOptions | SHARP.JS OPTIONS FOR GIF TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectBlurOptions | SHARP.JS OPTIONS FOR BLUR TRANSFORMATIONS | CHECK IT HERE | NO | - | | objectWatermarkOptions | OBJECT WITH OPTIONS FOR WATERMARK INSERTION | typeWatermarkOptions DESCRIBED BELLOW | NO | - |

  • typeWatermarkOptions TYPE:

| KEY | DESCRIPTION | TYPE | REQUIRED | DEFAULT | | - | - | - | - | - | | stringWatermarkFile | PATH OF THE IMAGE TO USE AS WATERMARK | string | YES | - | | numberOpacity | WATERMARK OPACITY | number BETWEEN 0 AND 1 | YES | - | | objectResizeOptions | SHARP.JS OPTIONS FOR RESIZING THE WATERMARK IMAGE | CHECK IT HERE | NO | - | | stringGravity | WATERMARK POSITION | 'centre' OR 'northwest' OR 'northeast' OR 'southeast' OR 'southwest' | NO | centre |