-
Notifications
You must be signed in to change notification settings - Fork 0
/
RESIZEDIRX.pl
executable file
·57 lines (49 loc) · 1.09 KB
/
RESIZEDIRX.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
use Image::Magick;
$FINALX=512;
$FINALY=$FINALX;
#arguments
if ($#ARGV == -1) {
print "usage: RESIZEDIRX.pl -i inputdir -r resx\n";
exit;
}
for ($arg=0;$arg <= $#ARGV;$arg++)
{
if (@ARGV[$arg] eq "-i")
{
$INDIR=@ARGV[$arg+1];
print "checking $INDIR\n";
}
if (@ARGV[$arg] eq "-r")
{
$FINALX=@ARGV[$arg+1];
print "final resolutionx $FINALX\n";
}
}
$INDIR =~ s/\///;
$OUTDIR="$INDIR\_$FINALX";
$cmd="mkdir $OUTDIR";
print "$cmd\n";
system $cmd;
@images=();
@images=`find $INDIR -maxdepth 1 | egrep -i \'[.]jpe?g$\'`;
#@images=`find $INDIR -maxdepth 1 | egrep -i \'[.]png$\'`;
$count=$#images+1;
print "found $count images\n";
$COUNT=0;
foreach $input_image (@images)
{
$COUNT++;
$CCOUNT=sprintf("ima.%04d.jpg",$COUNT);
chop $input_image;
@tmp=split(/\//,$input_image);
$fullimage=@tmp[$#tmp];
#get resolution
$i = Image::Magick->new;
$i->Read("$input_image");
$resx = $i->[0]->Get('width');
$resy = $i->[0]->Get('height');
$cmd="gmic \"$input_image\" -resize2dx $FINALX -o $OUTDIR/$CCOUNT";
print ("$cmd\n");
system $cmd;
}