favgen
v0.1.0
Published
CLI tool to generate a set of favicons from a single input file.
Downloads
4
Readme
This is a simple CLI tool to generate an optimized set of favicons from a single input file. Icons are optimized in terms of both size and quantity (nowadays you don't need that many of them). They are produced according to this article which served as an inspiration for the tool.
Use it like this: npx favgen /path/to/input -o /path/to/output
.
You can tweak the following settings by giving additional commands:
- output directory by providing
-o
option with a path (__favicon__
by default) - icon prefix by providing
--prefix
option with a name (favicon
by default) - colors palette size by providing
--colors
with a number between 2 and 256 - producing 16x16 .ico file by setting
--include16
flag
Input file can be in any of the following formats: JPEG, PNG, WebP, GIF, AVIF, TIFF or SVG (anything sharp library accepts).
By default, the following set of favicons is produced:
favicon.svg
if input file was SVG andfavicon.png
32x32 otherwisefavicon.ico
32x32favicon-192.png
192x192 (for Android devices)favicon-512.png
192x192 (for Android devices)apple-touch-icon.png
180x180 (original image is resized to 140x140 and 20px transparent padding is added on each side; rationale for this is given in the article)
Additionally, a sample manifest.webmanifest
file is produced which shows how favicons for Android devices are supposed to be included.
Besides that, PNG output is optimized by sharp
(which uses pngquant
) and SVG output is optimized by SVGO.
Also, color palette is reduced to 64 colors by default in order to reduce assets’ size.
The tool can be also used as API:
const { produceIcons } = require("favgen")
const inputFilePath = "favicon.svg"
const outputDirPath = "__favicons__"
const prefix = "favicon" // default value
const colorsPaletteSize = 64 // default value
const include16 = true // default is false
produceIcons({
inputFilePath,
outputDirPath,
prefix,
colorsPaletteSize,
include16,
})