/** * Prerequsite to run this script: * - ImageMagick installed * - Node (>= 12LTS) * * Save this somewhere on your machine as a node script (my choice is usually ~/bin/node_scripts) * * After alias it in zshrc as: * alias image_combine="node ~/node_scripts/image-combine.js" * * Use it like anywhere from command line like (by default combining images vertically): * imagecombine file1.png file2.png fileout.png [--horizontal] */ const { spawnSync } = require('child_process'); const directionMap = { '--vertical': '+append', '--horizontal': '-append' }; let userPreference = '--vertical'; if (process.argv.filter(x => x === '--horizontal').length) { userPreference = '--horizontal' } const cleanArgs = () => { const args = [...process.argv.slice(2)].filter(x => !x.startsWith('--')); return args; } const processArgs = cleanArgs(); if (!processArgs.length || processArgs.length < 3) { console.log('Please provide arguments in the following format: fileIn1.png fileIn2.png fileOut.png [--horizontal]') return; } console.log(`Running in ${userPreference} mode`); let sp = spawnSync('convert', [directionMap[userPreference], ...processArgs], { stdio: ['inherit', 0, 'inherit']}); if (!sp.status) { console.log(`Wonderful! Your image has been created! ;)`) }