#!/usr/bin/perl use warnings; use strict; use Image::Size; use Getopt::Std; my %opts; getopt ('n:s:', \%opts); die "Need options '-s ' to run!\n" unless defined $opts {'s'}; my $scale = $opts {s}; my $nameExt = $opts {'n'}; $nameExt = "_scaled" unless defined $opts {'n'}; # to not overwrite images my $convert = "/usr/bin/convert"; for my $imgname (@ARGV) { my ($width, $height) = imgsize ($imgname); unless ($width || $height) { print STDERR "Cannot get size from file $imgname\n"; next; } $width *= $scale; $height *= $scale; my $ofile = $imgname; $ofile =~ s/\.(.{2,4})$/$nameExt.$1/; my $cmd = sprintf "%s -scale %dx%d %s %s", $convert, $width, $height, $imgname, $ofile; print $cmd, "\n"; qx($cmd); }