Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

icon-gen

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icon-gen

Generate an icon files from the SVG or PNG files

  • 5.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
decreased by-0.92%
Maintainers
0
Weekly downloads
 
Created
Source

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.

PlatformIcon
Windowsapp.ico or specified name.
macOSapp.icns or specified name.
Faviconfavicon.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 icon-gen@2.1.0

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).

NameSizeICOICNSFav ICOFav PNG
16.png16x16
24.png24x24
32.png32x32
48.png48x48
57.png57x57
64.png64x64
72.png72x72
96.png96x96
120.png120x120
128.png128x128
144.png144x144
152.png152x152
195.png195x195
228.png228x228
256.png256x256
512.png512x512
1024.png1024x1024

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])

NameTypeDescription
srcStringPath of the SVG file or PNG files directory that becomes the source.
destStringDestination directory path.
optionsObjectsee: 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: {}
}
NameTypeDescription
reportBooleanDisplay the process reports. Default is false, disable a report.
icoObjectOutput setting of ICO file.
icnsObjectOutput setting of ICNS file.
faviconObjectOutput setting of Favicon file (PNG and ICO).

ico, icns

NameTypeDefaultDescription
nameStringappName of an output file.
sizesNumber[][Defaults...]Structure of an image sizes.

favicon

NameTypeDefaultDescription
nameStringfavicon-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.
pngSizesNumber[][Defaults...]Size structure of PNG files to output.
icoSizesNumber[][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

  • CHANGELOG

License

Keywords

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc