├── .gitignore ├── package.json ├── LICENSE ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | /test 4 | /icons -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-icon-maker", 3 | "version": "0.0.5", 4 | "description": "An icon generator to generate all the icon files needed for electron packaging", 5 | "bin": { 6 | "electron-icon-maker": "index.js" 7 | }, 8 | "main": "index.js", 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/jaretburkett/electron-icon-maker.git" 15 | }, 16 | "keywords": [ 17 | "electron", 18 | "icon", 19 | "maker", 20 | "icns", 21 | "png", 22 | "ico" 23 | ], 24 | "author": "Jaret Burkett (https://github.com/jaretburkett/)", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/jaretburkett/electron-icon-maker/issues" 28 | }, 29 | "homepage": "https://github.com/jaretburkett/electron-icon-maker", 30 | "dependencies": { 31 | "args": "^2.3.0", 32 | "icon-gen": "2.0.0", 33 | "jimp": "^0.14.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jaret Burkett 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## electron-icon-maker 2 | 3 | #### Global usage 4 | 5 | Install globally using 6 | 7 | ``` 8 | npm install -g electron-icon-maker 9 | ``` 10 | 11 | To use 12 | 13 | ``` 14 | electron-icon-maker --input=/absolute/path/file.png --output=./relative/path/to/folder 15 | ``` 16 | 17 | #### Local usage 18 | 19 | Install locally 20 | ``` 21 | npm install --save-dev electron-icon-maker 22 | ``` 23 | 24 | To use 25 | ``` 26 | ./node_modules/.bin/electron-icon-maker --input=/absolute/path/file.png --output=./relative/path/to/folder 27 | ``` 28 | 29 | #### Arguments 30 | 31 | ``` 32 | --output, -o = [String] Folder to create files 33 | --input, -i = [String] Path to PNG file 34 | ``` 35 | 36 | #### Recommendations 37 | Input file should be 1024px x 1024px or larger. Make sure it is a 1 to 1 aspect ratio on width to height. 38 | 39 | #### Output structure 40 | ``` 41 | [output dir] 42 | -[icons] 43 | -[mac] 44 | - icon.icns 45 | -[png] 46 | - 16x16.png 47 | - 24x24.png 48 | ... 49 | ... 50 | - 512x512.png 51 | - 1024x1024.png 52 | -[win] 53 | -icon.ico 54 | ``` -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const Jimp = require("jimp"); 4 | const args = require('args'); 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | const icongen = require( 'icon-gen' ); 8 | 9 | const pngSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024]; 10 | 11 | args 12 | .option('input', 'Input PNG file. Recommended (1024x1024)', './icon.png') 13 | .option('output', 'Folder to output new icons folder', './'); 14 | 15 | const flags = args.parse(process.argv); 16 | console.log(flags); 17 | 18 | // correct paths 19 | var input = path.resolve(process.cwd(), flags.input); 20 | var output = path.resolve(process.cwd(), flags.output); 21 | var o = output; 22 | var oSub = o.endsWith('/') ? o + 'icons/' : o + '/icons/'; 23 | var PNGoutputDir = oSub + 'png/'; 24 | 25 | const iconOptions = { 26 | type: 'png', 27 | report: true 28 | }; 29 | 30 | // do it 31 | createPNGs(0); 32 | 33 | 34 | // calls itself recursivly 35 | function createPNGs(position) { 36 | createPNG(pngSizes[position], function (err, info) { 37 | console.log(info); 38 | if (err) { 39 | if (err) throw new Error(err); 40 | } else if (position < pngSizes.length - 1) { 41 | // keep going 42 | createPNGs(position + 1); 43 | } else { 44 | // done, generate the icons 45 | const macDir = path.join(oSub, 'mac'); 46 | // make dir if does not exist 47 | if (!fs.existsSync(macDir)) { 48 | fs.mkdirSync(macDir); 49 | } 50 | const winDir = path.join(oSub, 'win'); 51 | // make dir if does not exist 52 | if (!fs.existsSync(winDir)) { 53 | fs.mkdirSync(winDir); 54 | } 55 | icongen(PNGoutputDir, macDir, { 56 | report: true, 57 | icns: { 58 | name: 'icon', 59 | sizes: [16, 32, 64, 128, 256, 512, 1024] 60 | }, 61 | } ).then( ( results ) => { 62 | icongen(PNGoutputDir, winDir, { 63 | report: true, 64 | ico: { 65 | name: 'icon', 66 | sizes: [16, 24, 32, 48, 64, 128, 256] 67 | }, 68 | } ) 69 | .then( ( results ) => { 70 | // console.log('\n ALL DONE'); 71 | // rename the PNGs to electron format 72 | console.log('Renaming PNGs to Electron Format'); 73 | renamePNGs(0); 74 | } ) 75 | .catch( ( err ) => { 76 | if (err) throw new Error(err); 77 | } ); 78 | } ) 79 | .catch( ( err ) => { 80 | if (err) throw new Error(err); 81 | } ); 82 | } 83 | }); 84 | } 85 | 86 | function renamePNGs(position){ 87 | var startName = pngSizes[position] + '.png'; 88 | var endName = pngSizes[position] + 'x' + pngSizes[position] + '.png'; 89 | fs.rename(PNGoutputDir + startName, PNGoutputDir + endName, function (err) { 90 | console.log('Renamed '+ startName + ' to '+endName); 91 | if (err) { 92 | throw err; 93 | } else if (position < pngSizes.length - 1){ 94 | // not done yet. Run the next one 95 | renamePNGs(position + 1); 96 | } else { 97 | console.log('\n ALL DONE'); 98 | } 99 | }); 100 | 101 | } 102 | 103 | function createPNG(size, callback) { 104 | var fileName = size.toString() + '.png'; 105 | 106 | // make dir if does not exist 107 | if (!fs.existsSync(output)) { 108 | fs.mkdirSync(output); 109 | } 110 | // make sub dir if does not exist 111 | if (!fs.existsSync(oSub)) { 112 | fs.mkdirSync(oSub); 113 | } 114 | // make dir if does not exist 115 | if (!fs.existsSync(PNGoutputDir)) { 116 | fs.mkdirSync(PNGoutputDir); 117 | } 118 | Jimp.read(input, function (err, image) { 119 | if (err) { 120 | callback(err, null); 121 | } 122 | image.resize(size, size) 123 | .write(PNGoutputDir + fileName, function (err) { 124 | var logger = 'Created ' + PNGoutputDir + fileName; 125 | callback(err, logger); 126 | }); 127 | }).catch(function (err) { 128 | callback(err, null); 129 | }); 130 | } 131 | --------------------------------------------------------------------------------