Created
July 3, 2019 08:37
-
-
Save rybarix/e9ae5dedff22765ae0be28c1f60810f8 to your computer and use it in GitHub Desktop.
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
const fs = require('fs') | |
const { exec } = require('child_process'); | |
const re = /(?<width>[0-9]+)x(?<height>[0-9]+)/ | |
function fileDims(fname) { | |
if (re.test(fname)) { | |
const { width, height } = re.exec(fname).groups | |
return { | |
width, height, | |
fileName: fname | |
} | |
} | |
return false | |
} | |
async function giveMeIcons({baseFile, fileNames, outputDirectory}) { | |
for await (const f of fileNames) { | |
const r = fileDims(f); | |
if (r !== false) { | |
console.log(`running : convert ${baseFile} -resize ${r.width}x${r.height} ${r.fileName}`) | |
exec(`convert ${baseFile} -resize ${r.width}x${r.height} ${r.fileName}`, (err, stdout, stderr) => { | |
if (err) { | |
// node couldn't execute the command | |
console.error(err.message, "Make sure you have image magic installed.") | |
return; | |
} | |
console.log('\x1b[36m%s\x1b[0m', r.fileName); | |
}); | |
} | |
} | |
exec('cp apple-touch-icon-180x180.png apple-touch-icon.png', (err, stdout, stderr) => { | |
if (err) { | |
console.error(err.message, "Failed to execute: 'cp apple-touch-icon-180x180.png ./apple-touch-icon.png'") | |
} | |
console.log('\x1b[36m%s\x1b[0m', "apple-touch-icon.png created from apple-touch-icon-180x180.png"); | |
}); | |
} | |
giveMeIcons({ | |
baseFile: 'android-chrome-512x512.png', | |
fileNames: [ | |
'android-chrome-192x192.png', | |
'apple-touch-icon-120x120.png', | |
'apple-touch-icon-152x152.png', | |
'apple-touch-icon-180x180.png', | |
'apple-touch-icon-60x60.png', | |
'apple-touch-icon-76x76.png', | |
'favicon-16x16.png', | |
'favicon-32x32.png', | |
'mstile-150x150.png', | |
'msapplication-icon-144x144.png', | |
'apple-touch-icon.png', | |
], | |
outputDirectory: '.' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment