#!/usr/bin/perl

use strict;
use warnings;

use Path::Class ();
use File::Copy ();

my @files = <*.jpg>;

use constant SHAVE_WIDTH => 715;

foreach my $f (@files) {
    my $path = Path::Class::file($f);
    my $reduced = Path::Class::file('reduced', $f);
    # If the image is close to the untrimmed size, resize it
    if(!-e $reduced) {
        print "Resize $path into $reduced\n";
        File::Copy::copy($path, $reduced) or die "Can't copy $path to $reduced: $!";
        system('/usr/bin/mogrify', '-shave', SHAVE_WIDTH . 'x0', $reduced);
    }
    else {
        print "$path: already resized - no change\n";
    }
}
