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