Skip to content

About

Pick a folder, set a size budget, get web-ready images. Local WebP/AVIF/JPEG/PNG compressor with a UI and a CLI. No uploads, no quota.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Image Optimizer

Pick a folder, set a size budget, get web-ready assets. Locally, in seconds.

Compress, resize and rename whole folders of images, video, SVG and Lottie. No uploads, no quota, no account. Originals are never touched.

Node License Runs locally

Image Optimizer interface: settings with Images, Video and SVG · Lottie tabs on the left; 97% saved and a list of optimized images, a video, SVGs and a Lottie file on the right

106.2 MB → 3.0 MB. Five 2x images, a 4K video, two SVGs and a Lottie file, in 21 seconds.


What it does

You drop in You get How
PNG, JPG, WebP, AVIF, TIFF WebP, AVIF, JPEG or PNG under the size you set Highest quality that fits your KB budget, optional max width
MP4, MOV, M4V, WebM .mp4 + .webm + a poster image H.264 and VP9, capped at 1920 px, muted, ready for a background video
SVG A smaller .svg svgo, with viewBox and <title> kept
Lottie JSON A minified .json + a .lottie Numbers rounded, then packed as dotLottie

Everything lands in an optimized/ folder next to the originals, with clean names if you want them.

Why

Design exports are heavy. A full-width hero exported from Figma at 2x is 5760 px wide and often 15–20 MB as PNG. The background video next to it is another 20–40 MB. Shipping them as is kills LCP. Fixing them by hand eats your afternoon, one tool per file type.

The usual options all have a catch:

Catch
TinyPNG and other online compressors Monthly limits. Client files, often under NDA, get uploaded to someone else's server.
Photoshop / Squoosh / HandBrake One file at a time, and a different app for each type.
Webflow's built-in conversion Images only, and it replaces the asset in place. The original is gone.

Image Optimizer runs the same encoders those tools use (libwebp, mozjpeg, libimagequant, AVIF, x264, VP9, svgo) on your own machine, on a whole folder at once.

Features

  • One folder, one button. Images, video, SVG and Lottie are picked up together and optimized in a single run.
  • Size budget for images. Set a max size in KB. Each image gets the highest quality that still fits.
  • Max width. Caps width without ever upscaling, separately for images and video. Usually saves more than lowering quality does.
  • Five image formats. WebP (default), AVIF, JPEG, PNG, or keep each file's format.
  • Web-ready video. MP4 and WebM side by side, a poster frame, no audio unless you ask, faststart so playback begins before the download ends.
  • Clean names. Hero Image@2x.png becomes acme-hero-image.webp. Optional project prefix, live preview before you run.
  • Before / after compare. Click any result to drag a slider between the original and the output. Images and SVG at fit size or 100 %, video and Lottie playing in sync on both sides.
  • Never bigger. An image in "keep" mode or an SVG that can't get smaller is copied as is.
  • Live progress. Results stream in file by file; video shows the encode percentage.
  • Two interfaces. A browser UI for people, a CLI for scripts and AI agents.
  • Private by design. The server binds to 127.0.0.1 only. Nothing leaves your machine.

Quick start

You need Node.js 18.17 or newer. Video also needs ffmpeg in your PATH (brew install ffmpeg or winget install ffmpeg). Everything else works without it.

Open the UI (no install, runs straight from GitHub):

npx github:oxmin-dev28/image-optimizer

The page opens in your browser at http://127.0.0.1:4747. Stop it with Ctrl+C in the terminal.

Or install it once and keep it:

git clone https://github.com/oxmin-dev28/image-optimizer.git
cd image-optimizer
npm install
npm start

Using the UI

  1. Choose a folder. A native folder dialog opens. Every supported file at the top level of that folder is picked up.
  2. Check the settings. One tab per file type, each showing how many such files the folder has:
    • Images. Format (WebP is the right default), max size in KB, max width in px, quality, optional sharpening.
    • Video. Sharp, Balanced or Small, max width (1920 unless you change it), whether to make a WebM copy, whether to keep audio.
    • SVG · Lottie. Nothing to set.
  3. Clean up names (optional). Add a project prefix and check the preview of the new names.
  4. Optimize. One run handles every type. Files land in <your folder>/optimized/.

Click any file name to compare it with the original:

Before and after compare dialog with a draggable slider between the original 21.4 MB PNG and the optimized 496 KB WebP

Settings are remembered between sessions. The page works on any screen size and follows your system's light or dark theme.

Mobile and light theme
The interface on a phone-sized screen in light theme, with the Video tab open

Using the CLI

Two commands, one per engine. Inside a cloned repo, node optimize.mjs and node media.mjs do the same. Both exit with 1 if any file failed, so they work in scripts and CI.

Images: optimize-images

npx -p github:oxmin-dev28/image-optimizer optimize-images [options] <folders | files | urls...>
# A whole folder → ~/Desktop/hero-images/optimized/
optimize-images ~/Desktop/hero-images

# Full-width section images: cap width, keep each under 300 KB
optimize-images --max-width 2560 --max-kb 300 ./exports

# Rename for a project while you're at it
optimize-images --prefix acme ./exports

# Specific files, AVIF, custom output folder
optimize-images -f avif -o ./dist hero.png team.jpg

# Straight from URLs (for example a Figma export link)
optimize-images "https://example.com/photo.png"
optimized/acme-hero-mountains.webp   21943KB → 496KB (-98%, q53, 3840x2400→1920x1200)
optimized/acme-team-offsite.webp     17740KB → 396KB (-98%, q80, 3840x2400→1920x1200)
5 done: 87768KB → 1731KB (-98%)
Option Short Default What it does
--format -f webp webp, avif, jpeg, png or keep
--max-kb -m none Size budget per image. Finds the highest quality ≥ 30 that fits.
--max-width -w none Max width in px. Never upscales.
--quality -q 80 Fixed quality, or the upper bound when --max-kb is set
--prefix -p none Prefix plus clean names: acme-hero-image.webp
--slug off Clean names without a prefix: hero-image.webp
--sharpen -s off Mild sharpening against softness after downscaling
--out -o ./optimized Output folder for files and URLs. A folder input always goes to <folder>/optimized/.
--help -h Show usage

Video, SVG and Lottie: optimize-media

npx -p github:oxmin-dev28/image-optimizer optimize-media [options] <folders | files...>
# Everything in a folder → <folder>/optimized/
optimize-media --prefix acme ./exports

# A background video at 1280 px, stronger compression, MP4 only
optimize-media --max-width 1280 --crf 30 --no-webm hero.mov
exports/Hero Loop.mp4               20127KB → acme-hero-loop.mp4 1886KB, acme-hero-loop.webm 1253KB, acme-hero-loop-poster.webp 276KB (-94%)
exports/Pattern Illustration.svg    224KB → acme-pattern-illustration.svg 99KB (-56%)
Option Short Default What it does
--max-width -w 1920 Max video width in px. Never upscales.
--crf 26 Video quality: lower is better and bigger. 23–30 is the useful range.
--audio off Keep the audio track. Background videos don't need one.
--no-webm off Skip the WebM. VP9 is the slow half of the job.
--prefix -p none Prefix plus clean names, same as for images
--slug off Clean names without a prefix
--out -o ./optimized Output folder for single files
--help -h Show usage

A .json file is only touched if it is a Lottie animation. Any other JSON in the folder is left alone.

Use cases

Figma → Webflow (or any site builder)

Export at 2x, point the tool at the export folder, use WebP · 500 KB · 2560 px · prefix = project name. Upload the optimized/ folder. Names are already clean and consistent for the asset library and the CMS.

Client sent 40 photos straight from a phone

12 MP JPEGs, 4–8 MB each, names like IMG_4821.JPG. Use WebP · 1920 px · 300 KB · prefix = page name. Done in under a minute, and nothing went through a third-party service.

Fixing a Lighthouse "Properly size images" warning

Download the flagged images, run them with a strict budget such as 200 KB · 1920 px, replace them on the site. The size budget does the guessing for you.

Grainy or film-look photography

Grain is noise, and noise is the first thing an encoder throws away. At quality 80 the picture comes out visibly smoother. Use quality 90 · max width 2560: on a 3840 px film photo that's 720 KB instead of 1.1 MB at full width, with the grain intact. Check it in the compare view at 100 %.

Logos, UI screenshots, flat illustrations

Use PNG. It's palette-quantized like TinyPNG, so it stays sharp with transparency and usually ends up 60–80 % smaller.

Projects under NDA

The whole point: files never leave your laptop. No upload, no third-party retention policy to explain to a client.

Background video for a hero

A 15 s 4K loop from the designer is 4 MB at best and often 40. Drop it in the folder: you get a 1920 px MP4 and WebM at about a quarter of the size, muted, plus a poster image to show while it loads.

SVG and Lottie straight from Figma or After Effects

Exports carry editor metadata and ten-digit coordinates. The same run strips them. In testing an illustration SVG lost 39 % and a 1 MB Lottie animation lost 45 % as .lottie. A logo that was already tidy barely changes.

AI agents and automation

Both commands are plain arguments in, one line per file out, and a non-zero exit code on failure. Claude, Cursor or a CI job can call it directly.

Recommended settings

Images

Content Format Max width Max size
Full-width hero or section background WebP 2560 300–500 KB
Content image, card, blog cover WebP 1600–1920 150–250 KB
Thumbnail or avatar WebP 800 50–100 KB
Logo, icon, UI screenshot PNG as is none
Smallest possible, modern browsers only AVIF as needed as needed

If a file reports over the size limit even at quality 30, the limit is too tight for that width. Lower the max width or raise the budget.

Video

Content Quality Max width Notes
Full-width background loop Balanced (--crf 26) 1920 Muted. Keep it under 15 s.
Small or decorative loop, mobile Small (--crf 30) 1280
Product demo people actually watch Sharp (--crf 23) 1920 Turn on audio if it has any.

In Webflow's Background Video element, upload the .mp4. In a custom <video> embed, list the .webm source first, the .mp4 second, and set the poster.

How it works

  • Images are built on sharp, which wraps the libvips C library. It's the same family of encoders as TinyPNG and Squoosh: libwebp, mozjpeg, libimagequant for PNG, and AVIF.
  • Size budget: a binary search over quality, from 30 up to your quality setting, about 5 encodes per image. It keeps the highest quality that fits.
  • Pipeline per image: EXIF orientation fix → optional resize → optional sharpen → encode → write. Four images run in parallel, which matches Node's default thread pool.
  • Video goes through your local ffmpeg: H.264 (-preset slow, faststart) and VP9, at constant quality instead of a fixed bitrate. The poster is the first frame as WebP.
  • SVG goes through svgo with its defaults, several passes.
  • Lottie numbers are rounded to 3 decimals and the JSON is minified, then zipped into a .lottie container.
  • The UI is a tiny local server (Node's built-in http, no frameworks) plus one HTML page with no build step and no external requests.

Benchmarks on a 12-core Mac:

Job Time
8 photos, 3840 × 2400 PNG, 102.9 MB total → WebP, 1920 px, 500 KB budget 6.8 s
100 images, 1920 × 1080 → WebP, 200 KB budget 47 s
One 2880 × 1600 image → AVIF with a budget ~18 s (AVIF is slow and uses all cores)
One 15 s 4K video → 1920 px MP4 + WebM + poster ~8 s
The folder in the screenshot: 5 images, a 10 s 4K video, 2 SVGs, a Lottie 21 s

Privacy and security

  • The server listens on 127.0.0.1 only. Nothing on your network can reach it.
  • Each launch generates a random token. Other websites open in your browser can't call the local API.
  • Requests with a foreign Host header are rejected, which blocks DNS rebinding.
  • The preview endpoint only serves files from the folder you picked and its optimized/ subfolder, with a sandbox policy so an SVG can't run scripts.
  • "Open folder" can only open a folder named optimized.

Limitations

  • Only the top level of a folder is processed. Subfolders are skipped.
  • The native folder dialog works on macOS and Windows. On Linux, use the CLI.
  • Video has no size budget, only a quality level. Its settings apply to every video in the folder.
  • Images embedded inside a Lottie file are not recompressed.
  • Browsers can't display TIFF, so TIFF sources have no compare view. They still get optimized. The same goes for video codecs your browser can't play, such as ProRes .mov: the compare shows only the optimized side.
  • No AI upscaling. If a source is too small, ask for a bigger one.
  • Port 4747 is used so your settings persist. If it's busy, a random port is used and settings won't carry over for that session.

Development

npm install
npm test      # size budget, max width, naming, SVG, Lottie, video
npm start     # UI

The project is four files: optimize.mjs (image engine and CLI), media.mjs (video, SVG and Lottie engine and CLI), ui.mjs (local server) and page.html (the interface). Dependencies: sharp, svgo, and lottie-web for Lottie previews in the UI.

License

MIT. Demo photos in the screenshots are from Unsplash via Lorem Picsum.


Built by Vlad Lypystii

About

Pick a folder, set a size budget, get web-ready images. Local WebP/AVIF/JPEG/PNG compressor with a UI and a CLI. No uploads, no quota.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages