Code Monkey home page Code Monkey logo

npm-icon-gen's Introduction

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

npm-icon-gen's People

Contributors

akabekobeko avatar atdrago avatar beijaflor avatar doug-a-brunner avatar ffflorian avatar jhicken avatar jordanmcdougall avatar lmm-git avatar makenowjust avatar marcbachmann avatar matchachoco010 avatar mifi avatar panther7 avatar quanglam2807 avatar rickysullivan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

npm-icon-gen's Issues

ICNS size adjustments

First, let me say thank you for this utility!! I needed a way to generate both .ico and .icns icons cross-platform, without special platform-dependent programs, and this utility is great! 💯

Now to the issue 😬

From Apple's documentation on .icns file creation:

A complete set consists of the following:

icon_16x16.png
[email protected]
icon_32x32.png
[email protected]
icon_128x128.png
[email protected]
icon_256x256.png
[email protected]
icon_512x512.png
[email protected]

From your documentation (and reading the code), I see two potential discrepancies. Please let me know if I'm wrong.

  1. You do not require a 16.png (16x16) image, which Apple recommends.
  2. You do require a 64.png (64x64) image, which Apple does not require. See correction in my next comment

What are your thoughts? And is fixing this just as simple as editing the array here?

Thank you!

Implement an output mode

Implement an outpit mode.

  • CLI option is -m or --mode
  • Value is all, ico, icns, favicon
  • Separated by a multiple if comma, e.g. -m ico,favicon
  • Default is 'all'

Test the CLI

Defines the parse of process.argv as a class, to test it.

Allow specifying icon file name

Currently, icons get saved to a directory as either "app.icns", "app.ico", or "favicon.ico". It makes sense to default the favicon to "favicon.ico", but users may want to use a name other than "app.icns" or "app.ico" for their application's icon. It would be nice to be able to specify the name of the saved icon file. My current workaround is to let the file write out as "app.ext" to a temp directory, then rename/move it using the user's preferred file name.

Relevant code block:
https://github.com/akabekobeko/npm-icon-gen/blob/master/src/lib/icon-generator.js#L123-L141

One possible implementation would be to add an object property to options. Something like:

icongen('./images', './dist', {
    modes: ['icns', 'ico'],
    names: { 'icns': 'my-icon' } // The ico file would default to "app"
});

CLI support

Support for command line interface.

$ icongen -i sample.svg -o ./ -p all

Drop transpile by Babel

ES 2015 support improved in Node v 6 and later. Since this npm uses only the function of ES2015, transpile by Babel is unnecessary.

However, as import is not supported, it is necessary to change to require.

PNG support

To support the icon generation from PNG.

  • PNG is 32bit only
  • Size and file name can be fixed

Icns not working

Great project!
I tried generating the sample.svg from test using
icon-gen -i sample.svg -m icns -o ./icon-dist -r
The icns file itself shows the icon in Finder, and I can open it in preview and see the sizes there, however when I try to apply it to a folder (or electron app) the icon doesn't show up.
node v 6.7.0, mac os sierra.
I attached generated icon.

Icon generetor from SVG:
src: /Users/mifi/Desktop/icon-test/sample.svg
dir: /Users/mifi/Desktop/icon-test/icon-dist
SVG to PNG:
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/16.png
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/32.png
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/64.png
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/128.png
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/256.png
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/512.png
Create: /var/folders/fv/s06vd5bd28n2ymghb4k7gq140000gn/T/ba757b91-be2e-41a5-970c-489d32b621ed/1024.png
ICNS:
Create: /Users/mifi/Desktop/icon-test/icon-dist/app.icns

app.icns.zip

Implement the FAVICON files generation

Size required below, from audreyr/favicon-cheat-sheet.

favicon.ico

Size Purpose
16x16 IE9 address bar, Pinned site Jump List/Toolbar/Overlay
24x24 IE9 Pinned site browser UI
32x32 New tab page in IE, taskbar button in Win 7+, Safari Read Later sidebar
48x48 Windows site icons
64x64 Windows site icons, Safari Reading List sidebar in HiDPI/Retina

PNG files

Size Name Purpose
32x32 favicon-32.png Certain old but not too old Chrome versions mishandle ico
57x57 favicon-57.png Standard iOS home screen (iPod Touch, iPhone first generation to 3G)
72x72 favicon-72.png iPad home screen icon
96x96 favicon-96.png GoogleTV icon
120x120 favicon-120.png iPhone retina touch icon (Change for iOS 7: up from 114x114)
128x128 favicon-128.png Chrome Web Store icon
144x144 favicon-144.png IE10 Metro tile for pinned site
152x152 favicon-152.png iPad retina touch icon (Change for iOS 7: up from 144x144)
195x195 favicon-195.png Opera Speed Dial icon
228x228 favicon-228.png Opera Coast icon

Drop the Node v4

Supports Node v4. use strict is necessary to use let, ...etc.

Drop the Node v4.

  • Dependent npm svg2png does not support Node v4
  • In Node LTS v4 was changed from Active to Maintenance to 2017-04-01

Fix a warning of consistent-return of ESLint

Example:

function sample() {
  return new Promise( ( resolve, reject ) => {
    const result = func();
    if( !( result ) ) { 
      return reject( new Error( 'Invalid result.' ) );
    }

    resolve();
  } );
}

It is an error to omit the modes in options

Example:

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

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

Error:

TypeError: Cannot read property 'forEach' of undefined
    at Function.generate (.../icon-gen/lib/icon-generator.js:161:12)
    at .../icon-gen/lib/icon-generator.js:84:25
    at .../icon-gen/lib/png-generator.js:92:11

Because the modes is undefined in IconGenerator.generate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.