crop.cjs 481 B

123456789
  1. const Jimp = require('jimp');
  2. const [input, out, x, y, width, height, outputWidth] = process.argv.slice(2);
  3. (async () => {
  4. const image = await Jimp.read(input);
  5. const part = image.crop(+x, +y, +width, +height);
  6. if (outputWidth) part.resize(+outputWidth, Jimp.AUTO);
  7. await part.writeAsync(out);
  8. console.log(`${input}: crop ${x},${y},${width},${height} -> ${out} (${part.bitmap.width}x${part.bitmap.height})`);
  9. })().catch(e => { console.error(e); process.exitCode = 1; });