Skip to content

Instantly share code, notes, and snippets.

@jdelibas
Created May 30, 2018 15:23
Show Gist options
  • Save jdelibas/6c139ba4bcdc98386fb2d107539bf8b7 to your computer and use it in GitHub Desktop.
Save jdelibas/6c139ba4bcdc98386fb2d107539bf8b7 to your computer and use it in GitHub Desktop.
Create psd (nodejs - imagemagick)
const path = require('path');
const fs = require('fs');
const { exec } = require('child_process');
let command = 'convert ';
const images = fs.readdirSync(path.resolve(__dirname, 'images')).filter(i => i.includes('jpg') || i.includes('jpeg')).map(i=> `images/${i}`)
command += images.map(i => {
const label = i.split('/')[1]
return `\\( -page +0+0 -label "${label}" ${i} -background none -mosaic -set colorspace RGB \\) `
}).join('')
command += `\\( -clone 0--1 -background none -mosaic \\) -alpha Off -reverse "abc.psd"`
exec(command, { cwd: __dirname }, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment