Skip to content

About

Batch optimisers for SVG and PNG files on Debian / WSL2 (Windows Subsystem for Linux)

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

optimize-svg-png

Batch optimisers for SVG and PNG files on Debian / WSL2 (Windows Subsystem for Linux).


optimize-svg

Converts text to path, inlines CSS styles and optimises all SVG files in a folder. Inkscape runs in shell mode (single launch), Python (lxml) and scour run in parallel on all CPU cores.

What it does

  • Step 1 – Inkscape: converts <text> to <path>, preserves original canvas (use --trim to fit canvas to drawing)
  • Step 2 – Python + lxml: parses SVG with lxml, inlines the presentation properties of simple CSS .class rules and removes the <style> block when no longer needed (files with @media, @keyframes, :hover... are left untouched)
  • Step 3 – scour: cleans and compresses SVG (metadata, comments, xml:space="preserve" and leftover blank lines, IDs, precision); width/height are always kept (use --keep-ids to leave IDs alone)
  • Step 4 – Python + lxml: verifies each output file is valid XML; restores from backup and marks [RESTORED] in the report if corrupted

Original files are backed up to <folder>_backup_svg before any modification.

Requirements

Inkscape, Python 3, python3-lxml and scour — installed automatically if missing.

Installation

mkdir -p ~/.local/bin
cp optimize_svg.bash ~/.local/bin/optimize_svg
chmod +x ~/.local/bin/optimize_svg

Usage

optimize_svg [--trim] [--keep-ids] <folder>

For full documentation see README_SVG.md.


optimize-png

Losslessly recompresses all PNG files in a folder and strips unnecessary embedded data. With --trim, also removes excess uniform margins.

What it does

  • oxipng: lossless recompression; removes ICC profiles, EXIF data and PNG metadata chunks (pixels stay identical, a file is never made larger). Use --keep-icc to keep the ICC profile
  • ImageMagick (only with --trim): trims uniform background pixels at edges with zero colour tolerance, then oxipng runs

Original files are backed up to <folder>_backup_png before any modification.

Requirements

oxipng — the latest release is downloaded automatically into /usr/local/bin if missing (x86_64 and aarch64). ImageMagick — needed only for --trim, or as a fallback if oxipng cannot be installed; installed automatically via apt when needed.

Installation

mkdir -p ~/.local/bin
cp optimize_png.bash ~/.local/bin/optimize_png
chmod +x ~/.local/bin/optimize_png

Usage

optimize_png [--trim] [--keep-icc] <folder>

For full documentation see README_PNG.md.


Common features

Both scripts share the same design principles:

  • process all files in a folder with a single command
  • run in parallel on all available CPU cores
  • create a backup of originals before making any change
  • stop safely if the backup folder already exists
  • print a Mode: line at start and a per-file size report with total space saved at the end
  • install missing dependencies automatically via apt

Windows users (WSL2)

Both scripts run on Windows via WSL2 with a Debian distribution.

wsl --install -d Debian

Windows drives are accessible under /mnt/:

optimize_svg /mnt/c/Users/YourName/Desktop/svg
optimize_png /mnt/c/Users/YourName/Desktop/png

About

Batch optimisers for SVG and PNG files on Debian / WSL2 (Windows Subsystem for Linux)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages