img2ico package
img2ico
A simple CLI tool and Python library to convert images into multi-resolution favicon (.ico) files.
Features
Convert PNG, JPG, WEBP, BMP to ICO
Optional SVG support (requires cairosvg)
Embed multiple icon sizes in one .ico file (16x16, 32x32, 48x48 by default)
Command-line interface with argparse
Example
Run from the command line:
img2ico input.png -o favicon.ico -s 16 32 48
Or use as a Python module:
from img2ico import convert_to_ico convert_to_ico(“logo.png”, “favicon.ico”, sizes=[(16, 16), (32, 32), (48, 48)])
License
MIT
- img2ico.convert_to_ico(input_path: Path, output_path: Path, sizes: Sequence[tuple[int, int]]) None
Convert an image file to a multi-resolution ICO file.
This function loads an image, converts it to RGBA (to preserve transparency), and saves it as an .ico file containing multiple icon resolutions.
- Parameters:
input_path (Path) – Path to the source image file (PNG, JPG, WEBP, BMP, etc.).
output_path (Path) – Path to the output .ico file.
sizes (Sequence[tuple[int, int]]) – A sequence of (width, height) tuples specifying which icon sizes to embed in the resulting .ico file. Example: [(16, 16), (32, 32), (48, 48)]
- Returns:
This function writes the .ico file to disk and prints a success message.
- Return type:
None
- Raises:
FileNotFoundError – If the input image file does not exist.
OSError – If the image cannot be opened or saved.
Example
>>> from pathlib import Path >>> convert_to_ico( ... input_path=Path("logo.png"), ... output_path=Path("favicon.ico"), ... sizes=[(16, 16), (32, 32), (48, 48)], ... ) ✅ Conversiosn complete: favicon.ico