Skip to content

Instantly share code, notes, and snippets.

@wei
Created June 20, 2016 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wei/647348259a274f568145e33862bc1208 to your computer and use it in GitHub Desktop.
Save wei/647348259a274f568145e33862bc1208 to your computer and use it in GitHub Desktop.
Generate Icons with SVG and Color Rounded Background
var COLORS = [
{iconColor: '#536D2F', bgColor: '#DDE2D5'},
{iconColor: '#5093A1', bgColor: '#DBE9EC'},
{iconColor: '#AF2F30', bgColor: '#EFD6D6'},
{iconColor: '#BE8341', bgColor: '#F2E6D9'},
{iconColor: '#784FA0', bgColor: '#E4DCEC'},
{iconColor: '#FFFFFF', bgColor: '#58B6E1'}
]
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
// String -> [String]
function fileList(dir) {
return fs.readdirSync(dir).reduce(function(list, file) {
var name = path.join(dir, file);
var isDir = fs.statSync(name).isDirectory();
return list.concat(isDir ? fileList(name) : [name]);
}, []);
}
function shuffle(r){for(var f,n,o=r.length;0!==o;)n=Math.floor(Math.random()*o),o-=1,f=r[o],r[o]=r[n],r[n]=f;return r}
var masterProcessList = []
fileList('svgs')
.map((file) => file.split(path.sep).slice(-1)[0])
.forEach(function(file) {
COLORS.forEach(function (colorObj) {
masterProcessList.push({colors: colorObj, svg: file})
})
})
masterProcessList = shuffle(masterProcessList)
var ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
ALPHABET.forEach(function(firstLetter) {
ALPHABET.forEach(function(secondLetter) {
ALPHABET.forEach(function(thirdLetter) {
if (masterProcessList.length < 1) { return }
var item = masterProcessList.pop()
child_process.execSync("convert -density 1200 -resize 250x250 -background none -fill '" + item.colors.iconColor + "' svgs/" + item.svg + " temp/" + item.svg + ".temp-icon.png");
child_process.execSync("convert -size 400x400 xc:none -fill '" + item.colors.bgColor + "' -draw 'circle 200,200 200,0' temp/" + item.svg + ".temp-bg.png");
child_process.execSync("mkdir -p " + "output/" + firstLetter + "/" + secondLetter);
child_process.execSync("composite -gravity center " +
"temp/" + item.svg + ".temp-icon.png" +
" " +
"temp/" + item.svg + ".temp-bg.png" +
" " +
"output/" + firstLetter + "/" + secondLetter + "/" + thirdLetter + ".png");
child_process.execSync("rm " + "temp/" + item.svg + ".temp-icon.png");
child_process.execSync("rm " + "temp/" + item.svg + ".temp-bg.png");
})
})
})
// convert -density 1200 -resize 250x250 -background none -fill '#754D9C' purse.svg purse.png
// convert -size 400x400 xc:none -fill '#E4DCEC' -draw 'circle 200,200 200,0' bg.png
// composite -gravity center purse.png bg.png avatar1.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment