-
Notifications
You must be signed in to change notification settings - Fork 33
/
mirror_images.pl
68 lines (51 loc) · 1.21 KB
/
mirror_images.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
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
# Author: Trizen
# Date: 04 June 2024
# https://github.com/trizen
# Mirror a given list of images (horizontal flip).
use 5.036;
use Imager qw();
use File::Find qw(find);
use Getopt::Long qw(GetOptions);
my $img_formats = '';
my @img_formats = qw(
jpeg
jpg
png
);
sub usage ($code) {
local $" = ",";
print <<"EOT";
usage: $0 [options] [dirs | files]
options:
-f --formats=s,s : specify more image formats (default: @img_formats)
example:
perl $0 ~/Pictures
EOT
exit($code);
}
GetOptions('f|formats=s' => \$img_formats,
'help' => sub { usage(0) },)
or die("Error in command line arguments");
push @img_formats, map { quotemeta } split(/\s*,\s*/, $img_formats);
my $img_formats_re = do {
local $" = '|';
qr/\.(@img_formats)\z/i;
};
sub mirror_image ($image) {
my $img = Imager->new(file => $image) or do {
warn "Failed to load <<$image>>: ", Imager->errstr();
return;
};
$img->flip(dir => "h");
$img->write(file => $image);
}
@ARGV || usage(1);
find {
no_chdir => 1,
wanted => sub {
(/$img_formats_re/o && -f) || return;
say "Mirroring: $_";
mirror_image($_);
}
} => @ARGV;