SVG_to_ICONS is a command-line tool designed to transform SVG files into high-quality icon sets for both Windows and macOS. With features for automatic dark theme generation and multi-resolution output, this tool streamlines icon production, ensuring compatibility across platforms with minimal effort.
SVG to ICONS
SVG to ICONS is a powerful command-line utility designed to streamline the conversion of SVG files into high-quality, production-ready icon sets for both Windows and macOS environments, complete with automatic dark theme variants. This tool simplifies the process of generating multiple icon formats and sizes, ensuring versatility and adaptability in UI design.
Output Structure
When converting an SVG file (for example, logo.svg), the tool produces a dedicated subfolder named after the file, containing the following:
logo/
├── logo.ico # Windows light theme (multi-resolution: 16–256px)
├── logo_dark.ico # Windows dark theme
├── logo_mac_template.png # macOS menu bar, black (system auto-adapts light/dark)
├── logo_mac_template@2x.png # macOS menu bar, black, Retina
y├── logo_mac_template_dark.png # macOS menu bar, white (for Electron / non-native)
├── logo_mac_template_dark@2x.png # macOS menu bar, white, Retina
└── png/
├── light/
│ ├── logo_16x16.png
│ ├── logo_32x32.png
│ └── ...up to 512x512
└── dark/
└── ...same sizes, inverted
Requirements
To get started, ensure the following Python packages are installed:
pip install cairosvg pillow
For macOS, if the installation of cairosvg fails, it may be necessary to install Cairo using Homebrew:
brew install cairo
For Windows, the GTK3 runtime must be installed to support Cairo; alternatively, consider using the Windows Subsystem for Linux (WSL).
Usage Examples
The invocation of the tool is straightforward:
# Generate icons from a single SVG file
python generate_icons.py logo.svg
# Generate icons from multiple SVG files
python generate_icons.py icon1.svg icon2.svg icon3.svg
# Using a glob pattern (bash/zsh)
python generate_icons.py assets/*.svg
Options
| Flag | Description |
|---|---|
--ico-only | Generate only ICO files |
--mac-only | Generate macOS template icons only |
--png-only | Generate PNG files only |
--no-dark | Skip dark theme variants |
--png-sizes SIZES | Define custom PNG sizes (default: 16,32,64,128,256,512) |
--out-dir DIR | Define the root output directory (default: same directory as each SVG) |
The --ico-only, --mac-only, and --png-only flags are mutually exclusive.
Additional Examples
To illustrate more advanced usages:
# Generate only ICO files, skip dark variants, and output to the ./dist directory
python generate_icons.py *.svg --ico-only --no-dark --out-dir ./dist
# Specify custom PNG sizes for output
python generate_icons.py logo.svg --png-only --png-sizes 32,64,128
# Generate macOS icons for all SVGs in a specified folder
python generate_icons.py assets/*.svg --mac-only
Platform Considerations
macOS
The generated files named *Template.png will automatically adapt to the menu bar's appearance without requiring additional code modifications for light or dark mode support. The _dark variants provide compatibility for frameworks that do not support the template convention:
| Framework | Recommended file |
|---|---|
| SwiftUI/AppKit | *_mac_template.png only |
| Electron | Switch between black and white icons with nativeTheme.on('updated') |
| Tauri | Toggle appearance on tauri::api::app::appearance_changed |
Windows
Since Windows system tray icons do not automatically adjust to theme changes, it is essential to detect the active theme at runtime and swap icons accordingly using appropriate event listeners and APIs.
No comments yet.
Sign in to be the first to comment.