Last active
December 14, 2020 22:19
-
-
Save xwipeoutx/926b38c2f08fd0957e59d23c619955d7 to your computer and use it in GitHub Desktop.
Generates all the UWP icons with sensible naming, based of a couple initial files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let imageConversion = require("image-conversion"); | |
var fs = require("fs"); | |
let jimp = require("jimp"); | |
let ImageJs = require("image-js"); | |
let output = "public/images/icon"; | |
const scales = [100, 125, 150, 200, 240, 400]; | |
const iconTargetSizes = [16,24,32,48,256]; | |
const iconTargetDecorations = ['unplated_targetsize', 'targetsize']; | |
const icons = [ | |
makeIcon("square.png", "BadgeLogo", 24, 24, "png"), | |
makeIcon("square.png", "StoreLogo", 50, 50, "png"), | |
makeIcon("square.png", "Square30x30Logo", 30, 30, "png"), | |
makeIcon("square.png", "Square44x44Logo", 44, 44, "png"), | |
makeIcon("square.png", "Square70x70Logo", 70, 70, "png"), | |
makeIcon("square.png", "Square71x71Logo", 71, 71, "png"), | |
makeIcon("square.png", "Square150x150Logo", 150, 150, "png"), | |
makeIcon("square.png", "Square310x310Logo", 310, 310, "png"), | |
makeIcon("wide.png", "Wide310x150Logo", 310, 150, "jpg"), | |
makeIcon("wide.png", "SplashScreen", 620, 300, "jpg"), | |
]; | |
function makeIcon(source, name, width, height, extension) { | |
return { | |
source, | |
name, | |
width: width, | |
height: height, | |
extension | |
}; | |
} | |
async function outputSingle(sourcePath, width, height, outputFile) { | |
// Jimp seems better at resizing | |
let jimpImg = await jimp.read(sourcePath); | |
jimpImg = jimpImg.resize(width, height); | |
jimpImg = await jimpImg.writeAsync(outputFile); | |
// image-js seems better at file sizes | |
let img2 = await ImageJs.read(outputFile); | |
await ImageJs.write(outputFile, img2); | |
console.log("Saved " + outputFile) | |
} | |
async function doIt() { | |
for (var i=0;i<icons.length;i++) { | |
let icon = icons[i]; | |
for (var j=0;j<scales.length;j++) { | |
let scale = scales[j]; | |
let sourcePath = `raw-icons/${icon.source}` | |
let outputFile = `${output}/${icon.name}.scale-${scale}.${icon.extension}`; | |
let scaledWidth = Math.ceil((scale * icon.width)/100); | |
let scaledHeight = Math.ceil((scale * icon.height)/100); | |
await outputSingle(sourcePath, scaledWidth, scaledHeight, outputFile); | |
} | |
} | |
for (var i=0;i<iconTargetSizes.length;i++) { | |
let targetSize = iconTargetSizes[i]; | |
for (var j=0;j<iconTargetDecorations.length;j++) { | |
let decoration = iconTargetDecorations[j]; | |
let sourcePath = `raw-icons/square.png` | |
let outputFile = `${output}/Square44x44Logo-${decoration}-${targetSize}.png`; | |
await outputSingle(sourcePath, targetSize, targetSize, outputFile); | |
} | |
} | |
} | |
doIt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment