#!/usr/bin/env node

const sharp = require('sharp');

const args = process.argv.slice(2);

if (args.length < 6) {
  console.error('Usage: crop-image.js <input> <output> <left> <top> <width> <height>');
  console.error('Example: crop-image.js photo.jpg cropped.jpg 0 95 1376 578');
  process.exit(1);
}

const [input, output, left, top, width, height] = args;

sharp(input)
  .extract({
    left: parseInt(left, 10),
    top: parseInt(top, 10),
    width: parseInt(width, 10),
    height: parseInt(height, 10)
  })
  .toFile(output)
  .then(info => {
    console.log(`Saved: ${output} (${info.width}x${info.height})`);
  })
  .catch(err => {
    console.error('Error:', err.message);
    process.exit(1);
  });
