Generate an icon files from the SVG or PNG files
Last updated 2 years ago by akabeko .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install icon-gen 
SYNC missed versions from official npm registry.


Support Node of LTS npm version Build Status Document Standard - JavaScript Style Guide

Generate an icon files from the SVG or PNG files.

Node.js requirements

This module depends on svg2png. Therefore we need Node v6 or later. The following is a quotation from README of svg2png.

svg2png uses the latest in ES2015 features, and as such requires a recent version of Node.js. Only the 6.x series onward is supported.

Support formats

Supported the output format of the icon are following.

Platform Icon
Windows app.ico or specified name.
macOS app.icns or specified name.
Favicon favicon.ico and favicon-XX.png.


$ npm install icon-gen


SVG and PNG are automatically selected from the input path. If the path indicates a file SVG, if it is a directory it will be a PNG folder.


SVG files are rendering to PNG file in svg2png. Rendering files is output to a temporary directory of the each OS.

Rendering of svg2png is run by phantomjs. Please use the PNG directory If the rendering quality there is a problem.

const icongen = require('icon-gen');

icongen('./sample.svg', './icons', { report: true })
.then((results) => {
.catch((err) => {


Generate an icon files from the directory of PNG files.

const icongen = require('icon-gen');

icongen('./images', './icons', , { report: true })
.then((results) => {
} )
.catch((err) => {

Required PNG files is below. Favicon outputs both the ICO and PNG files (see: audreyr/favicon-cheat-sheet).

Name Size ICO ICNS Fav ICO Fav PNG
16.png 16x16
24.png 24x24
32.png 32x32
48.png 48x48
57.png 57x57
64.png 64x64
72.png 72x72
96.png 96x96
120.png 120x120
128.png 128x128
144.png 144x144
152.png 152x152
195.png 195x195
228.png 228x228
256.png 256x256
512.png 512x512
1024.png 1024x1024

To make it a special size configuration, please specify with ico,icns and favicon options.

Node API


icongen is promisify function.

icongen(src, dest[, options])

Name Type Description
src String Path of the SVG file or PNG files directory that becomes the source.
dest String Destination directory path.
options Object see: Options.


const options = {
  report: true,
  ico: {
    name: 'app',
    sizes: [16, 24, 32, 48, 64, 128, 256]
  icns: {
    name: 'app',
    sizes:  [16, 32, 64, 128, 256, 512, 1024]
  favicon: {
    name: 'favicon-',
    sizes:  [32, 57, 72, 96, 120, 128, 144, 152, 195, 228],
    ico: [16, 24, 32, 48, 64]

If all image options (ico,icns, favicon) are omitted, all images are output with their default settings.

// Output an all images with default settings
const options = {
  report: true

If individual image option is omitted, default setting is used. If there is a format that you do not want to output, specify others and omit that image.

// Without ICNS
const options = {
  report: true,
  ico: {}
  favicon: {}
Name Type Description
report Boolean Display the process reports. Default is false, disable a report.
ico Object Output setting of ICO file.
icns Object Output setting of ICNS file.
favicon Object Output setting of Favicon file (PNG and ICO).

ico, icns

Name Type Default Description
name String app Name of an output file.
sizes Number[] [Defaults...] Structure of an image sizes.


Name Type Default Description
name String favicon- Prefix of an output PNG files. Start with the alphabet, can use - and _. This option is for PNG. The name of the ICO file is always favicon.ico.
sizes Number[] [Defaults...] Size structure of PNG files to output.
ico Number[] [Defaults...] Structure of an image sizes for ICO.


Usage: icon-gen [OPTIONS]

Generate an icon from the SVG or PNG file.
If '--ico', '--icns', '--favicon' is not specified, everything is output in the standard setting.

-h, --help    Display this text.
-v, --version Display the version number.
-i, --input   Path of the SVG file or PNG file directory.
-o, --output  Path of the output directory.
-r, --report  Display the process reports.
              Default is disable.
--ico         Output ICO file with the specified 'name' and 'sizes'.
              ex. --ico name=foo sizes=16,32,128
--icns        Output ICO file with the specified 'name' and 'sizes'.
              ex. --icns name=bar sizes=32,1024
--favicon     Output Favicon files with the specified 'ico', 'name' and 'sizes'.
              'ico' is the size of the ICO file.
              'name' is the prefix of the PNG file. Start with the alphabet, can use '-' and '_'.
              'sizes' is the size of the PNG file.
              ex. '--favicon ico=16,32 name=favicon- sizes=16,32,128'

$ icon-gen -i sample.svg -o ./dist -r
$ icon-gen -i ./images -o ./dist -r
$ icon-gen -i sample.svg -o ./dist --ico --icns
$ icon-gen -i sample.svg -o ./dist --ico --favicon ico=16,32 name=favicon- sizes=16,32,128

See also:



Current Tags

  • 2.0.0                                ...           latest (2 years ago)

19 Versions

  • 2.0.0                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.5                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago

Copyright 2014 - 2017 © taobao.org |