use warnings;
use experimental 'signatures';
-our $VERSION = '1.02';
+our $VERSION = '1.03';
sub new ($class, $target) {
bless \$target, $class;
);
}
-sub convert ($imgpath, $thumbpath, $cmds, $xyres) {
+sub convert ($imgpath, $thumbpath, $cmds, $xyres = 0) {
#my ($w, $h) = $imgpath->dimensions;
#my $aspect = 3/2; # $xyres
my @cmds = @{$cmds};
'-strip', -quality => '60%', -interlace => 'plane',
-gravity => defined $cmds ? 'northwest' : 'center',
@cmds,
- -resize => "$xyres^", -extent => $xyres,
+ $xyres ? (-resize => "$xyres^", -extent => $xyres) : (),
$thumbpath
);
#!/usr/bin/env perl
use 5.014;
use warnings;
+use lib $0 =~ s{[^/]+$}{..}r; # project root
+use Shiar_Sheet::ImagePrep '1.03';
my $failcount = 0;
if @crop > 2;
unshift @cmds, -chop => "$crop[0]%x$crop[1]%";
}
- unshift @cmds, -gravity => 'northwest' if @cmds;
- push @cmds, '-strip', -gravity => 'north', -quality => 60;
+ push @cmds, -gravity => 'north';
my @cmdwebp = (-resize => '630x420^', -extent => '630x420', -quality => 30);
my @cmdjpeg = (-resize => '300x200^', -extent => '300x200');
- system(convert => $src, @cmds, @cmdjpeg, "../$name.jpg" ) == 0 and
- system(convert => $src, @cmds, @cmdwebp, "../$name.webp") == 0
- or $failcount += warn "error creating $name.jpg from $src\n";
+ eval {
+ my $image = Shiar_Sheet::ImagePrep->new($src);
+ $image->convert("../$name.jpg", [@cmds, @cmdjpeg]);
+ $image->convert("../$name.webp", [@cmds, @cmdwebp]);
+ } or do {
+ warn "error creating image:\n";
+ warn ref $@ eq 'ARRAY' ? $@->[1] : $@ if $@;
+ $failcount++;
+ };
}
exit $failcount;