• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Icon file generator for Windows, macOS, Web

npm-icon-gen

Support Node of LTS npm version test

Generate an icon files from the SVG or PNG files.

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.

Installation

$ npm install icon-gen

Usage

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

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

const icongen = require('icon-gen')

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

Stopped using svg2png because of its dependency on phantomjs, which is deprecated.

The quality of PNG generated from SVG will change, so if you need the previous results, use icon-gen v2.1.0 (old version).

$ npm install [email protected]

In the future, I may add SVG to PNG conversion by Chromium via puppeteer-core in addition to sharp.

PNG

Generate an icon files from the directory of PNG files.

const icongen = require('icon-gen')

icongen('./images', './icons', { report: true })
  .then((results) => {
    console.log(results)
  })
  .catch((err) => {
    console.error(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

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.

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-',
    pngSizes: [32, 57, 72, 96, 120, 128, 144, 152, 195, 228],
    icoSizes: [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.

favicon

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.
pngSizes Number[] [Defaults...] Size structure of PNG files to output.
icoSizes Number[] [Defaults...] Structure of an image sizes for ICO.

CLI

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.

Options:
  -i, --input <Path>           Path of the SVG file or PNG file directory.
  -o, --output <Path>          Path of the output directory.
  -r, --report                 Display the process reports, default is disable.
  --ico                        Output ICO file with default settings, option is "--ico-*".
  --ico-name <Name>            ICO file name to output.
  --ico-sizes [Sizes]          PNG size list to structure ICO file
  --icns                       Output ICNS file with default settings, option is "--icns-*".
  --icns-name <Name>           ICO file name to output.
  --icns-sizes [Sizes]         PNG size list to structure ICNS file
  --favicon                    Output Favicon files with default settings, option is "--favicon-*".
  --favicon-name <Name>        prefix of the PNG file. Start with the alphabet, can use "-" and "_"
  --favicon-png-sizes [Sizes]  Sizes of the Favicon PNG files
  --favicon-ico-sizes [Sizes]  PNG size list to structure Favicon ICO file
  -v, --version                output the version number
  -h, --help                   output usage information

Examples:
  $ 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 --ico-name sample --ico-sizes 16,32
  $ icon-gen -i sample.svg -o ./dist --icns --icns-name sample --icns-sizes 16,32
  $ icon-gen -i sample.svg -o ./dist --favicon --favicon-name=favicon-  --favicon-png-sizes 16,32,128 --favicon-ico-sizes 16,32

See also:
  https://github.com/akabekobeko/npm-icon-gen

ChangeLog

License

More Repositories

1

examples-electron

Examples for Electron applications.
TypeScript
216
star
2

redmine-theme-minimalflat2

Minimal and flat theme for Redmine.
SCSS
149
star
3

examples-web-app

Examples of web applications and tools.
JavaScript
48
star
4

npm-cross-conf-env

To cross-platform the "config" and root variable reference of package.json in npm-scripts.
TypeScript
26
star
5

examples-ios-fmdb

Example for the FMDB
Objective-C
19
star
6

npm-wpxml2md

Convert the WordPress XML file to Markdown files.
JavaScript
13
star
7

redmine-theme-minimalflat

Minimal and flat design Redmine theme.
HTML
13
star
8

Examples-iOS

This repository is intended to publish a example of iOS.
Objective-C
13
star
9

examples-nw

Examples of node-webkit.
JavaScript
11
star
10

electron-release-notes-ja-private-edition

Electron release notes translated into Japanese (Private Edition).
6
star
11

redmine-theme-starter

Starter kit for theme of Redmine.
CSS
6
star
12

npm-gatsby-remark-copy-relative-linked-files

Copies local files relative linked to/from markdown to your public folder with preserve directory structure.
TypeScript
6
star
13

npm-xlsx-extractor

Extracte a columns/rows from XLSX file.
TypeScript
5
star
14

env-create-book

Environment by creating a book with Vivliostyle/vivliostyle-savepdf.
TypeScript
5
star
15

npm-svg2png

Create PNG file from SVG file with puppeteer-core. Use the specified revision or installed Chromium for PNG file creation.
TypeScript
4
star
16

npm-slack-log2md

Slack log file (JSON) to Markdown.
TypeScript
3
star
17

wp-theme-minimalflat2

WordPress theme for http://akabeko.me/blog
HTML
2
star
18

wp-note-flexible2

It is a WordPress plug-in that provides the annotation feature of WP-Note http://wordpress.org/plugins/wp-note/ compatible.
JavaScript
2
star
19

examples-vivliostyle-pagedjs

This is a project to compare and verify Vivliostyle and Paged.js.
1
star
20

yue-release-notes-ja-private-edition

yue release notes translated into Japanese (Private Edition).
1
star
21

Owl

Owl is metadata ( ASF, ID3v2/v2, ...etc ) editor library.
C#
1
star
22

wordpress-theme-minimalflat

Minimal and flat design WordPress theme.
PHP
1
star
23

test-remark-parse-html

Test the parsing of HTML tags by remark-parse.
TypeScript
1
star
24

eslintrc-editor

It is a tool to edit the configuration file .eslintrc of ESLint in the GUI.
1
star
25

Examples-Android

The repository has published a sample project for Android.
Java
1
star