line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Image::Generator; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
82532
|
use strict; |
|
4
|
|
|
|
|
27
|
|
|
4
|
|
|
|
|
175
|
|
4
|
4
|
|
|
4
|
|
26
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
119
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2237
|
use English; |
|
4
|
|
|
|
|
17782
|
|
|
4
|
|
|
|
|
30
|
|
7
|
4
|
|
|
4
|
|
4084
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
32526
|
|
|
4
|
|
|
|
|
115
|
|
8
|
4
|
|
|
4
|
|
326
|
use File::Basename qw(fileparse); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
2160
|
|
9
|
4
|
|
|
4
|
|
12178
|
use Getopt::Std; |
|
4
|
|
|
|
|
272
|
|
|
4
|
|
|
|
|
289
|
|
10
|
4
|
|
|
4
|
|
1852
|
use Image::Random; |
|
4
|
|
|
|
|
276778
|
|
|
4
|
|
|
|
|
186
|
|
11
|
4
|
|
|
4
|
|
2677
|
use Image::Select; |
|
4
|
|
|
|
|
85914
|
|
|
4
|
|
|
|
|
195
|
|
12
|
4
|
|
|
4
|
|
48
|
use Readonly; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
2439
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
15
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY_STR => q{}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = 0.03; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Constructor. |
20
|
|
|
|
|
|
|
sub new { |
21
|
2
|
|
|
2
|
1
|
1549
|
my $class = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Create object. |
24
|
2
|
|
|
|
|
9
|
my $self = bless {}, $class; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Object. |
27
|
2
|
|
|
|
|
43
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Run script. |
31
|
|
|
|
|
|
|
sub run { |
32
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Process arguments. |
35
|
1
|
|
|
|
|
13
|
$self->{'_opts'} = { |
36
|
|
|
|
|
|
|
'h' => 0, |
37
|
|
|
|
|
|
|
'i' => $EMPTY_STR, |
38
|
|
|
|
|
|
|
's' => '1920x1080', |
39
|
|
|
|
|
|
|
'v' => 0, |
40
|
|
|
|
|
|
|
}; |
41
|
1
|
50
|
33
|
|
|
9
|
if (! getopts('hi:s:v', $self->{'_opts'}) || @ARGV < 1 |
|
|
|
33
|
|
|
|
|
42
|
|
|
|
|
|
|
|| $self->{'_opts'}->{'h'}) { |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
128
|
print STDERR "Usage: $0 [-h] [-i input_dir] [-s size] [-v]". |
45
|
|
|
|
|
|
|
"\n\t[--version] output_file\n\n"; |
46
|
1
|
|
|
|
|
37
|
print STDERR "\t-h\t\tPrint help.\n"; |
47
|
1
|
|
|
|
|
15
|
print STDERR "\t-i input_dir\tInput directory with ". |
48
|
|
|
|
|
|
|
"images (default value is nothing).\n"; |
49
|
1
|
|
|
|
|
12
|
print STDERR "\t-s size\t\tSize (default value is ". |
50
|
|
|
|
|
|
|
"1920x1080).\n"; |
51
|
1
|
|
|
|
|
12
|
print STDERR "\t-v\t\tVerbose mode.\n"; |
52
|
1
|
|
|
|
|
11
|
print STDERR "\t--version\tPrint version.\n"; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
5
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
$self->{'_output_file'} = $ARGV[0]; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Check size. |
59
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'s'} !~ m/^(\d+)x(\d+)$/ms) { |
60
|
0
|
|
|
|
|
|
err 'Bad size value.', 'Value', $self->{'_opts'}->{'s'}; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
$self->{'_width'} = $1; |
63
|
0
|
|
|
|
|
|
$self->{'_height'} = $2; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Run. |
66
|
0
|
|
|
|
|
|
eval { |
67
|
0
|
|
|
|
|
|
my (undef, undef, $suffix) = fileparse($self->{'_output_file'}, |
68
|
|
|
|
|
|
|
qr{\..*$}); |
69
|
0
|
|
|
|
|
|
$suffix =~ s/^\.//g; |
70
|
0
|
|
|
|
|
|
my $type = lc($suffix); |
71
|
0
|
0
|
|
|
|
|
if ($type eq 'jpg') { |
72
|
0
|
|
|
|
|
|
$type = 'jpeg'; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Images from directory. |
76
|
0
|
|
|
|
|
|
my $ig; |
77
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'i'} ne $EMPTY_STR) { |
78
|
|
|
|
|
|
|
$ig = Image::Select->new( |
79
|
|
|
|
|
|
|
'debug' => ($self->{'_opts'}->{'v'} ? 1 : 0), |
80
|
|
|
|
|
|
|
'height' => $self->{'_height'}, |
81
|
|
|
|
|
|
|
'path_to_images' => $self->{'_opts'}->{'i'}, |
82
|
|
|
|
|
|
|
'type' => $type, |
83
|
0
|
0
|
|
|
|
|
'width' => $self->{'_width'}, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Random image. |
87
|
|
|
|
|
|
|
} else { |
88
|
|
|
|
|
|
|
$ig = Image::Random->new( |
89
|
|
|
|
|
|
|
'height' => $self->{'_height'}, |
90
|
|
|
|
|
|
|
'type' => $type, |
91
|
0
|
|
|
|
|
|
'width'=> $self->{'_width'}, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
$ig->create($self->{'_output_file'}); |
95
|
|
|
|
|
|
|
}; |
96
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
97
|
0
|
|
|
|
|
|
err 'Cannot create image.'; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |