forked from LMS-Community/slimserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdresize.pl
executable file
·134 lines (102 loc) · 2.72 KB
/
gdresize.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/perl
#
# Stand-alone interface to GDResizer
#
# TODO:
# Better error handling
#
use strict;
use FindBin qw($Bin);
use lib $Bin;
use constant RESIZER => 1;
use constant SLIM_SERVICE => 0;
use constant PERFMON => 0;
use constant SCANNER => 0;
use constant WEBUI => 0;
use constant ISWINDOWS => ( $^O =~ /^m?s?win/i ) ? 1 : 0;
use constant DEBUG => ( grep { /--debug/ } @ARGV ) ? 1 : 0;
use constant LOCALFILE => 0;
use constant NOMYSB => 1;
BEGIN {
use Slim::bootstrap ();
Slim::bootstrap->loadModules( ['Image::Scale'], [] );
};
use Getopt::Long;
use Slim::Utils::GDResizer;
my $help;
our ($file, $url, @spec, $cacheroot, $cachekey, $faster, $debug);
my $ok = GetOptions(
'help|?' => \$help,
'file=s' => \$file,
'url=s' => \$url,
'spec=s' => \@spec,
'cacheroot=s' => \$cacheroot,
'cachekey=s' => \$cachekey,
'faster' => \$faster,
'debug' => \$debug,
);
if ( !$ok || $help || ( !$file && !$url ) || !@spec ) {
require Pod::Usage;
Pod::Usage::pod2usage(1);
}
# Download URL to a temp file
my $fh;
if ( $url ) {
require File::Temp;
require LWP::UserAgent;
$fh = File::Temp->new();
$file = $fh->filename;
my $ua = LWP::UserAgent->new( timeout => 5 );
$debug && warn "Downloading URL to $file\n";
my $res = $ua->get( $url, ':content_file' => $file );
if ( !$res->is_success ) {
die "Unable to download $url: " . $res->status_line . "\n";
}
}
# Setup cache
my $cache;
if ( $cacheroot && $cachekey ) {
require Cache::FileCache;
$cache = Cache::FileCache->new( {
namespace => 'Artwork',
cache_root => $cacheroot,
directory_umask => umask(),
} );
}
eval {
Slim::Utils::GDResizer->gdresize(
file => $file,
debug => $debug,
faster => $faster,
cache => $cache,
cachekey => $cachekey,
spec => \@spec,
);
};
if ( $@ ) {
die "$@\n";
}
exit 0;
__END__
=head1 NAME
gdresize.pl - Standalone artwork resizer
=head1 SYNOPSIS
Resize normal image file or an audio file's embedded tags:
Options:
--file [ /path/to/image.jpg | /path/to/image.mp3 ]
Supported file types:
Images: jpg, jpeg, gif, png, bmp
Audio: see Audio::Scan documentation
--url http://...
--spec <width>x<height>_<mode>[.ext] ...
Mode is one of:
m: max (default)
p: pad (same as max)
o: original
Multiple spec arguments may be specified to resize in series.
--cacheroot [dir] Cache resulting image in a FileCache called
'Artwork' located in dir
--cachekey [key] Use this key for the cached data.
Note: spec value will be appended to the cachekey
if multiple spec values were supplied.
=cut