2018-05-21 19:07:05 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
// You need to npm install svg2png for this to work
|
|
|
|
var svg2png = require('svg2png');
|
|
|
|
|
|
|
|
var svgdir = "svg";
|
|
|
|
var outputdir = "out";
|
|
|
|
|
|
|
|
const svgNS = "http://www.w3.org/2000/svg";
|
|
|
|
|
|
|
|
const icons = {
|
|
|
|
heart: `
|
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`,
|
|
|
|
smallheart: `
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. # # # .
|
|
|
|
. . # . .
|
|
|
|
. . . . .`,
|
|
|
|
happy: `
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
# . . . #
|
|
|
|
. # # # .`,
|
|
|
|
sad: `
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
# . . . #`,
|
|
|
|
confused: `
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
# . # . #`,
|
|
|
|
angry: `
|
|
|
|
# . . . #
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
# # # # #
|
|
|
|
# . # . #`,
|
|
|
|
asleep: `
|
|
|
|
. . . . .
|
|
|
|
# # . # #
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
. . . . .`,
|
|
|
|
surprised: `
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
. . # . .`,
|
|
|
|
silly: `
|
|
|
|
# . . . #
|
|
|
|
. . . . .
|
|
|
|
# # # # #
|
|
|
|
. . . # #
|
|
|
|
. . . # #`,
|
|
|
|
fabulous: `
|
|
|
|
# # # # #
|
|
|
|
# # . # #
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. # # # .`,
|
|
|
|
meh: `
|
|
|
|
# # . # #
|
|
|
|
. . . . .
|
|
|
|
. . . # .
|
|
|
|
. . # . .
|
|
|
|
. # . . .`,
|
|
|
|
yes: `
|
|
|
|
. . . . .
|
|
|
|
. . . . #
|
|
|
|
. . . # .
|
|
|
|
# . # . .
|
|
|
|
. # . . .`,
|
|
|
|
no: `
|
|
|
|
# . . . #
|
|
|
|
. # . # .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
# . . . #`,
|
|
|
|
triangle: `
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
. . . . .`,
|
|
|
|
lefttriangle: `
|
|
|
|
# . . . .
|
|
|
|
# # . . .
|
|
|
|
# . # . .
|
|
|
|
# . . # .
|
|
|
|
# # # # #`,
|
|
|
|
chessboard: `
|
|
|
|
. # . # .
|
|
|
|
# . # . #
|
|
|
|
. # . # .
|
|
|
|
# . # . #
|
|
|
|
. # . # .`,
|
|
|
|
diamond: `
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
# . . . #
|
|
|
|
. # . # .
|
|
|
|
. . # . .`,
|
|
|
|
smalldiamond: `
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
. . # . .
|
|
|
|
. . . . .`,
|
|
|
|
square: `
|
|
|
|
# # # # #
|
|
|
|
# . . . #
|
|
|
|
# . . . #
|
|
|
|
# . . . #
|
|
|
|
# # # # #`,
|
|
|
|
smallsquare: `
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
. # . # .
|
|
|
|
. # # # .
|
|
|
|
. . . . .`,
|
|
|
|
scissors: `
|
|
|
|
# # . . #
|
|
|
|
# # . # .
|
|
|
|
. . # . .
|
|
|
|
# # . # .
|
|
|
|
# # . . #`,
|
|
|
|
tshirt: `
|
|
|
|
# # . # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. # # # .
|
|
|
|
. # # # .`,
|
|
|
|
rollerskate: `
|
|
|
|
. . . # #
|
|
|
|
. . . # #
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # . # .`,
|
|
|
|
duck: `
|
|
|
|
. # # . .
|
|
|
|
# # # . .
|
|
|
|
. # # # #
|
|
|
|
. # # # .
|
|
|
|
. . . . .`,
|
|
|
|
house: `
|
|
|
|
. . # . .
|
|
|
|
. # # # .
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. # . # .`,
|
|
|
|
tortoise: `
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
# # # # #
|
|
|
|
. # . # .
|
|
|
|
. . . . .`,
|
|
|
|
butterfly: `
|
|
|
|
# # . # #
|
|
|
|
# # # # #
|
|
|
|
. . # . .
|
|
|
|
# # # # #
|
|
|
|
# # . # #`,
|
|
|
|
stickfigure: `
|
|
|
|
. . # . .
|
|
|
|
# # # # #
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
# . . . #`,
|
|
|
|
ghost: `
|
|
|
|
. # # # .
|
|
|
|
# . # . #
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
# . # . #`,
|
|
|
|
sword: `
|
|
|
|
. . # . .
|
|
|
|
. . # . .
|
|
|
|
. . # . .
|
|
|
|
. # # # .
|
|
|
|
. . # . .`
|
|
|
|
,
|
|
|
|
giraffe: `
|
|
|
|
# # . . .
|
|
|
|
. # . . .
|
|
|
|
. # . . .
|
|
|
|
. # # # .
|
|
|
|
. # . # .`,
|
|
|
|
skull: `
|
|
|
|
. # # # .
|
|
|
|
# . # . #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. # # # .`,
|
|
|
|
umbrella: `
|
|
|
|
. # # # .
|
|
|
|
# # # # #
|
|
|
|
. . # . .
|
|
|
|
# . # . .
|
|
|
|
# # # . .`,
|
|
|
|
snake: `
|
|
|
|
# # . . .
|
|
|
|
# # . # #
|
|
|
|
. # . # .
|
|
|
|
. # # # .
|
|
|
|
. . . . .`,
|
|
|
|
rabbit: `
|
|
|
|
# . # . .
|
|
|
|
# . # . .
|
|
|
|
# # # # .
|
|
|
|
# # . # .
|
|
|
|
# # # # .`,
|
|
|
|
cow: `
|
|
|
|
# . . . #
|
|
|
|
# . . . #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`,
|
|
|
|
quarternote: `
|
|
|
|
. . # . .
|
|
|
|
. . # . .
|
|
|
|
. . # . .
|
|
|
|
# # # . .
|
|
|
|
# # # . .`,
|
|
|
|
eigthnote: `
|
|
|
|
. . # . .
|
|
|
|
. . # # .
|
|
|
|
. . # . #
|
|
|
|
# # # . .
|
|
|
|
# # # . .`,
|
|
|
|
pitchfork: `
|
|
|
|
# . # . #
|
|
|
|
# . # . #
|
|
|
|
# # # # #
|
|
|
|
. . # . .
|
|
|
|
. . # . .`,
|
|
|
|
target: `
|
|
|
|
. . # . .
|
|
|
|
. # # # .
|
|
|
|
# # . # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(icons).forEach(icon => {
|
|
|
|
const data = icons[icon];
|
|
|
|
const hexLiteral = data
|
|
|
|
.replace(/[ \n`\(\)]/gi, '');
|
|
|
|
|
|
|
|
var svg = `<svg xmlns="http://www.w3.org/2000/svg" height="200" width="200">`;
|
|
|
|
const width = 200;
|
|
|
|
const height = 200;
|
2018-10-06 00:09:44 +02:00
|
|
|
//svg += '<rect width="100%" height="100%" fill="#176CBF"/>';
|
2018-05-21 19:07:05 +02:00
|
|
|
for (var i = 0; i < 5; i++) {
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
const hexItemVal = hexLiteral[(i * 5) + j] ? hexLiteral[(i * 5) + j] == '#' : false;
|
|
|
|
const x = j * (width / 5);
|
|
|
|
const y = i * (height / 5);
|
2018-10-06 00:09:44 +02:00
|
|
|
svg += `<rect y="5" x="5" width="30" height="30" rx="5" transform="translate(${x},${y})"
|
|
|
|
style="${hexItemVal ? 'fill:#fff;' : 'fill: #4BA6FF;'}"/>\n`; //#006CC2
|
2018-05-21 19:07:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
svg += `</svg>`;
|
|
|
|
const svgPath = path.join(svgdir, icon + ".svg");
|
2018-10-06 00:09:44 +02:00
|
|
|
fs.writeFile(svgPath, svg, { encoding: 'utf8', flag: 'w' }, function(err, result) {
|
|
|
|
if (err) console.log("error writing to file");
|
|
|
|
});
|
2018-05-21 19:07:05 +02:00
|
|
|
|
|
|
|
const sourceBuffer = Buffer.from(svg, 'utf8');
|
|
|
|
svg2png(sourceBuffer, { width: 200, height: 200 })
|
2018-10-06 00:09:44 +02:00
|
|
|
.then(buffer => fs.writeFile(path.join(outputdir, icon + "-icon.png"), buffer, { encoding: 'utf8', flag: 'w' }, function (err, result) {
|
|
|
|
if (err) console.log("error writing to file");
|
|
|
|
}))
|
2018-05-21 19:07:05 +02:00
|
|
|
.catch(e => console.error(e));
|
|
|
|
});
|