Skip to content

fxxr/picture-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

picture-converter

npm version License: MIT GitHub stars

Convert old image formats (.png, .jpg, .gif) to modern, efficient formats (.webp, .avif) automatically.

Built with sharp — fast, reliable, and production-ready.

🚀 Features

  • 🔍 Recursively scans folders for images
  • 🧠 Skips already converted files (unless forced)
  • ⚙️ Configurable encoding options for WebP and AVIF
  • 🪶 Handles GIF → WebP animation conversion

📦 Installation

npm install picture-converter

🧑‍💻 Usage

Import and run

import convertImages from 'picture-converter'

await convertImages('./images')

Conversions:

  • .png and .jpg.webp and .avif
  • .gif.webp
  • Existing .webp and .avif files are skipped unless you set forceRewrite to true.

With Options

await convertImages('./assets', {
  animated: true,
  webp: {quality: 85},
  avif: {quality: 50, effort: 6},
}, true)

Parameters:

Name Type Default Description
inputDir string required Directory containing images
conversionOptions {animated?: boolean, webp?: WebpOptions; avif?: AvifOptions} {} Passed directly to sharp
forceRewrite boolean false Whether to overwrite existing .webp / .avif

Example Folder Structure

Before:

images/
├── photo.jpg
├── logo.png
└── funny.gif

After:

images/
├── photo.jpg
├── photo.webp
├── photo.avif
├── logo.png
├── logo.webp
├── logo.avif
├── funny.gif
└── funny.webp

🧠 How It Works

  1. Scans directories recursively.
  2. Detects base formats (.jpg, .png, .gif).
  3. Checks whether .webp/.avif versions already exist.
  4. Converts missing ones using sharp.
  5. Skips or overwrites depending on forceRewrite.

⚙️ API Reference

convertImages(
  inputDir: string,
  conversionOptions?: {
    animated?: boolean
    webp?: sharp.WebpOptions
    avif?: sharp.AvifOptions
  },
  forceRewrite?: boolean
): Promise<{converted: number, skipped: number, failed: number}>

Contributing

Contributions, issues, and feature requests are welcome!
Open an issue or submit a pull request.

Related

  • sharp — High performance Node.js image processing
  • imagemin — Legacy image optimization toolkit

License

MIT © Anatoly Nechaev

About

Convert PNG, JPG, and GIF images to modern WebP and AVIF formats automatically using sharp — fast, lightweight, and TypeScript-powered.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors