-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathresize-icons.pl
executable file
·48 lines (37 loc) · 995 Bytes
/
resize-icons.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
#!/usr/bin/perl
#
# resize-icons.pl [path] [spec]
# Resize all icon.png files found to the given spec
use strict;
use FindBin;
use constant RESIZER => 1;
use lib (
"$FindBin::Bin/../server",
"$FindBin::Bin/../server/CPAN",
"$FindBin::Bin/../server/CPAN/arch/5.10/darwin-thread-multi-2level",
);
use File::Next;
use File::Spec::Functions qw(catfile);
use Slim::Utils::GDResizer;
my $path = shift || die "No path found";
my $spec = shift || die "No spec found";
my $files = File::Next::files( {
file_filter => sub { /icon\.png/ },
}, $path );
my ($width, $height, $mode) = $spec =~ /^([^x]+)x([^_]+)_(\w)$/;
while ( my $file = $files->() ) {
my ($ref, $format) = Slim::Utils::GDResizer->resize(
file => $file,
width => $width,
height => $height,
mode => $mode,
);
if ( $ref ) {
my $outfile = $file;
$outfile =~ s/\.png$/_${spec}.png/;
open my $fh, '>', $outfile or die "Cannot open $outfile: $!";
print $fh $$ref;
close $fh;
print $file . "\n";
}
}