An open API service indexing awesome lists of open source software.

https://github.com/andmitr/favicon-generator-cli

A Node.js CLI tool that generates a full set of favicons from PNG and SVG source images. Outputs optimized icons in multiple sizes and formats (ICO, Apple Touch Icon, Android Chrome, etc.) ready for cross-browser use.
https://github.com/andmitr/favicon-generator-cli

cli favicon icons image-processing nodejs tools utility

Last synced: 3 months ago
JSON representation

A Node.js CLI tool that generates a full set of favicons from PNG and SVG source images. Outputs optimized icons in multiple sizes and formats (ICO, Apple Touch Icon, Android Chrome, etc.) ready for cross-browser use.

Awesome Lists containing this project

README

          

# Favicon Generator CLI

A Node.js CLI tool that generates a full set of favicons from PNG and SVG source images. Outputs optimized icons in
multiple sizes and formats (ICO, Apple Touch Icon, Android Chrome, etc.) ready for cross-browser use.

[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&logo=opensource)](LICENSE)

[![npm version](https://img.shields.io/npm/v/favicon-generator-cli?style=flat-square&logo=npm)](https://www.npmjs.com/package/favicon-generator-cli)
[![Docker](https://img.shields.io/badge/ghcr.io-container-blue?style=flat-square&logo=docker)](https://github.com/andmitr/favicon-generator-cli/pkgs/container/favicon-generator-cli)

## Table of Contents

- [Features](#features)
- [Dependencies](#dependencies)
- [Installation](#installation)
- [Usage](#usage)
- [Sponsorship](#sponsorship)
- [License](#license)

## Features

- **Generated files:**
- `favicon.ico` (multi-size: 16px, 32px, 48px, 256px from PNG)
- `favicon.svg` (optimized from source SVG)
- `favicon-16x16.png`
- `favicon-32x32.png`
- `favicon-48x48.png`
- `apple-touch-icon.png` (180×180px)
- `icon-192.png` and `icon-512.png` (for Android/PWA manifest)
- **PNG and SVG input:** Accepts both formats as source material. Defaults
to `./favicon_src.png` and `./favicon_src.svg`.
- **Image optimization:** Uses `sharp` for PNG resizing,
`imagemin` + `imagemin-pngquant` for PNG compression, `svgo` for SVG
optimization, and `png2icons` for ICO generation.
- **Custom output directory:** Specify an output path with `--dist`, or let
the tool create a `favicons_xxxx` directory in the current working directory.
- **CLI arguments:** Simple command-line interface with `--help` for usage
details.
- **Error handling:** Reports missing source files and image processing
failures.

> **Note:** This tool does not generate a 512×512 maskable icon for PWA
> safe-zone compliance. This must be created separately using a tool
> like [maskable.app](https://maskable.app/editor). Make sure your PWA
> manifest references the maskable icon alongside other icons.

## Dependencies

- [Node.js](https://nodejs.org/) v24 LTS (tested and recommended version, specified in `.nvmrc`)
- Docker (if you choose to run the tool via container)
- npm packages (installed automatically with the tool):
- imagemin
- imagemin-pngquant
- sharp
- svgo
- png2icons

## Installation

### From npm

```bash
sudo npm install -g favicon-generator-cli
```

### From GitHub

```bash
sudo npm install -g git+https://github.com/andmitr/favicon-generator-cli.git
```

### From Docker Registry (GitHub Container Registry)

```bash
docker pull ghcr.io/andmitr/favicon-generator-cli:latest
```

To use a shorter image name locally, create a tag:

```shell
docker tag ghcr.io/andmitr/favicon-generator-cli:latest favgen
```

### Uninstall

```bash
sudo npm uninstall -g favicon-generator-cli
```

### Troubleshooting: libvips conflict

If you have libvips installed system-wide, sharp installation may fail. Use SHARP_IGNORE_GLOBAL_LIBVIPS=1 to bypass it:

```bash
# From npm
sudo SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g favicon-generator-cli

# From GitHub
sudo SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g git+https://github.com/andmitr/favicon-generator-cli.git

# Run without installation
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npx --package=favicon-generator-cli favgen
```

## Usage

```bash
favgen [--png ] [--svg ] [--dist ]
```

### Docker

```bash
docker run --rm -v "$PWD:/app" ghcr.io/andmitr/favicon-generator-cli:latest [--png ] [--svg ] [--dist ]
```

If you created the local favgen image tag:

```shell
docker run --rm -v "$PWD:/app" favgen [--png ] [--svg ] [--dist ]
```

#### Shortcuts (Alias)

To avoid typing the long Docker command every time, add this alias to your ~/.bashrc or ~/.zshrc:

```shell
alias favgend='docker run --rm -v "$PWD:/app" ghcr.io/andmitr/favicon-generator-cli:latest'
```

Then you can use it just like the native command:

```shell
favgend --help
favgend --dist favicons
```

### Run without installation

```bash
npx --package=favicon-generator-cli favgen [--png ] [--svg ] [--dist ]
```

### Arguments

| Argument | Alias | Default | Description |
|----------|-------|-------------------|--------------------------------------|
| --png | -p | ./favicon_src.png | Path to the source PNG image |
| --svg | -s | ./favicon_src.svg | Path to the source SVG image |
| --dist | -d | ./favicons_xxxx | Output directory for generated files |
| --help | -h | — | Show help message and exit |

### Examples
```bash
# Custom source files and output directory
favgen --png ./myicon.png --svg ./myicon.svg --dist ./favs

# Default source files, custom output directory
favgen --dist icons
```

### HTML Usage

Add the generated favicons to the `` of your HTML:
```html

```
Reference `icon-192.png` and `icon-512.png` in your `manifest.webmanifest`.

## Sponsorship

[![Boosty](https://img.shields.io/badge/Boosty-F15F2C?style=for-the-badge&logo=boosty&logoColor=white)![Support](https://img.shields.io/badge/Support%20me-grey?style=for-the-badge)](https://boosty.to/andmitr/donate)

![Bitcoin](https://img.shields.io/badge/Bitcoin-F7931A?style=flat&logo=bitcoin&logoColor=white&logoSize=auto)

```
1CCnwAvJYEoDVGM7vsBg2Q99cF9EHtBVaY
```

![Tether](https://img.shields.io/badge/Tether%20(USDT%20ETH)-168363?style=flat&logo=tether&logoColor=white&logoSize=auto)

```
0x54f0ccc6b2987de454f69f2814fc9202bcfb74fe
```

## License

MIT Licensed. See [LICENSE](LICENSE) for details.