Skip to content

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

img2icon

Converts a JPG, PNG, or HEIC into all common icon/logo formats in one step.

Report Issue · Request Feature

License Platform GitHub release (latest by date)


Table of Contents


Description

C++23 CMake Platform

Converts a JPG, PNG, or HEIC into all common icon/logo formats in one step.

Output Description
logo.ico Multi-resolution ICO (16 · 32 · 48 · 64 · 256 px)
logo_92x92.png PNG — app icon, small
logo_256x256.png PNG — app icon, medium
logo_512x512.png PNG — app icon, large
logo_512x512.webp WebP — app icon, large (default quality 85)
logo_92x92.avif AVIF — app icon, small (default quality 75)
logo_256x256.avif AVIF — app icon, medium (default quality 75)
logo_512x512.avif AVIF — app icon, large (default quality 75)
logo.svg SVG wrapper with embedded base64 PNG data-URI

All PNG/ICO outputs are center-padded to exact square dimensions (aspect ratio is preserved, excess area is transparent).


Prerequisites

Dependency macOS Ubuntu / Debian
ImageMagick ≥ 7 brew install imagemagick sudo apt install libmagick++-dev
CMake ≥ 3.25 brew install cmake sudo apt install cmake
C++23 compiler Xcode 15 / clang 17 GCC 14 / clang 17
CLI11 auto-fetched by CMake auto-fetched by CMake

Build

Option A — CMake (recommended)

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
# optional:
sudo cmake --install build

Option B — Single-command (no CMake)

c++ -std=c++23 \
    $(Magick++-config --cxxflags --libs) \
    -ICLI11/include \
    src/img2icon.cpp -o img2icon

Grab CLI11 header: curl -Lo CLI11/include/CLI/CLI.hpp \ https://github.com/CLIUtils/CLI11/releases/download/v2.4.2/CLI11.hpp


Usage

img2icon [OPTIONS]

Options:
  -i, --input    PATH   Input image *.jpg | *.jpeg | *.png | *.heic [required]
  -o, --output   DIR    Output directory (created if absent) [required]
  -n, --name     NAME   Base filename for outputs            [default: logo]
      --no-bg           Remove background → transparent
      --fuzz     0-100  Tolerance for background removal     [default: 15]
  --webp-quality 0-100  WebP quality                         [default: 85]
  --avif-quality 0-100  AVIF quality                         [default: 75]
  -h, --help            Show this help

Examples

# Basic conversion
./img2icon -i photo.jpg -o ./icons

# Custom base name
./img2icon -i brand.png -o ./dist -n myapp

# Transparent background (e.g. white background photo)
./img2icon -i logo.png -o ./icons --no-bg

# Aggressive background removal for noisy scans
./img2icon -i scan.jpg -o ./icons --no-bg --fuzz 25

Background removal notes

--no-bg performs a corner flood-fill: it samples each of the four corner pixels and flood-fills outward using the specified --fuzz tolerance. This works well for images with a solid or near-solid background colour.

  • --fuzz 0 — exact colour match only (rarely useful)
  • --fuzz 15 — default; good for clean white/solid backgrounds
  • --fuzz 25+ — for scanned or slightly graduated backgrounds

For complex backgrounds (photos, gradients), consider pre-processing the image in a dedicated editor before passing it to img2icon.


SVG output

The .svg file embeds the full-resolution source as a base64 PNG data-URI. This is a raster-in-vector format — it is not a true vector graphic, but it is valid, self-contained SVG that renders at any scale in browsers and design tools without external file dependencies.


(back to top)

Authors and License

License Distributed under the MIT License. See LICENSE for more information.

Copyright (c) 2026 ZHENG Robert

Authors

  • Zheng Robert - Core Development

Code Contributors

Contributors

Zheng Robert


🖖

About

Converts JPG/HEIC/PNG to ICO, PNG, WebP, AVIF variants and SVG

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages