line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VLGal::File::MMagic; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw( VLGal::File ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
94
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
5
|
use DirHandle; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
8
|
1
|
|
|
1
|
|
5
|
use Error qw(:try); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
172
|
use File::Spec; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
10
|
1
|
|
|
1
|
|
513
|
use Image::Magick; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Package version |
13
|
|
|
|
|
|
|
our ($VERSION) = '$Revision: 0.01 $' =~ /\$Revision:\s+([^\s]+)/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
VLGal::File::MMagic - Vincenzo's little gallery MMagic file |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
TODO |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 ABSTRACT |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Vincenzo's little gallery MMagic file |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
C describes properties of Vincenzo's little gallery MMagic file. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item new( [ OPT_HASH_REF ] ) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Creates a new C object. C is a hash reference used to pass initialization options. On error an exception C is thrown. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Options for C inherited through package B> may include: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item B> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Passed to L. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item B> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Passed to L. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item B> |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Passed to L. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item generate() |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This method is an implementation from package C. Generates the C files and image files that implement the gallery. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
The file organisation leaves the original organisation as intact as possible. That is, in each directory one file C and one directory C<.vlgal> are claimed. The file C is the entry point for the gallery. Directory C<.vlgal> contains generated images in lower resolution and quality and C files required by the gallery. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item get_basename() |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This method is inherited from package C. Returns the file's base name. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item get_dirname() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This method is inherited from package C. Returns the file's directory name. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item get_super_dir() |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This method is inherited from package C. Returns the super directory in the file system. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item mk_fs_name() |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This method is inherited from package C. Makes the file systemn name of the object usinf C and C. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item mk_vlgal_dir_name() |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This method is inherited from package C. Makes the name of the C<.vlgal> directory. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item set_basename(VALUE) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This method is inherited from package C. Set the file's base name. C is the value. On error an exception C is thrown. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item set_dirname(VALUE) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This method is inherited from package C. Set the file's directory name. C is the value. On error an exception C is thrown. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item set_super_dir(VALUE) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This method is inherited from package C. Set the super directory in the file system. C is the value. On error an exception C is thrown. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item VALUE must be a (sub)class of: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=over |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item VLGal::Directory |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SEE ALSO |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L, |
118
|
|
|
|
|
|
|
L, |
119
|
|
|
|
|
|
|
L, |
120
|
|
|
|
|
|
|
L, |
121
|
|
|
|
|
|
|
L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 BUGS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
None known (yet.) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 HISTORY |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
First development: September 2003 |
130
|
|
|
|
|
|
|
Last update: October 2003 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Vincenzo Zocca |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright 2003 by Vincenzo Zocca |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This file is part of the C module hierarchy for Perl by |
143
|
|
|
|
|
|
|
Vincenzo Zocca. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The VLGal module hierarchy is free software; you can redistribute it |
146
|
|
|
|
|
|
|
and/or modify it under the terms of the GNU General Public License |
147
|
|
|
|
|
|
|
as published by the Free Software Foundation; either version 2 of |
148
|
|
|
|
|
|
|
the License, or (at your option) any later version. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
The VLGal module hierarchy is distributed in the hope that it will |
151
|
|
|
|
|
|
|
be useful, but WITHOUT ANY WARRANTY; without even the implied |
152
|
|
|
|
|
|
|
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
153
|
|
|
|
|
|
|
See the GNU General Public License for more details. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
156
|
|
|
|
|
|
|
along with the VLGal module hierarchy; if not, write to |
157
|
|
|
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
158
|
|
|
|
|
|
|
Boston, MA 02111-1307 USA |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub generate { |
163
|
|
|
|
|
|
|
my $self = shift; |
164
|
|
|
|
|
|
|
my $prev_file = shift; |
165
|
|
|
|
|
|
|
my $next_file = shift; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Make the .vlgal directory |
168
|
|
|
|
|
|
|
( -d $self->mk_vlgal_dir_name() ) || mkdir( $self->mk_vlgal_dir_name() ); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# For each size, make a file in the .vlgal directory |
171
|
|
|
|
|
|
|
my $i = -1; |
172
|
|
|
|
|
|
|
foreach my $size ( VLGal::Style->instance()->get_size() ) { |
173
|
|
|
|
|
|
|
$i++; |
174
|
|
|
|
|
|
|
# Make size directory if necessary |
175
|
|
|
|
|
|
|
my $size_dir = File::Spec->catfile( |
176
|
|
|
|
|
|
|
$self->get_dirname(), |
177
|
|
|
|
|
|
|
'.vlgal', |
178
|
|
|
|
|
|
|
$size->get_basename() |
179
|
|
|
|
|
|
|
); |
180
|
|
|
|
|
|
|
( -d $size_dir ) || mkdir($size_dir); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# Make resised file name |
183
|
|
|
|
|
|
|
my $fs_name_size = File::Spec->catfile( |
184
|
|
|
|
|
|
|
$size_dir, |
185
|
|
|
|
|
|
|
$self->get_basename() |
186
|
|
|
|
|
|
|
); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Write the html file |
189
|
|
|
|
|
|
|
if ( $i ) { |
190
|
|
|
|
|
|
|
my $super_html_dir; |
191
|
|
|
|
|
|
|
if ( $i == 1 ) { |
192
|
|
|
|
|
|
|
$super_html_dir = '../..'; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else { |
195
|
|
|
|
|
|
|
$super_html_dir = '../../.vlgal/' . $size->get_basename(); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
$self->generate_html( |
198
|
|
|
|
|
|
|
"$fs_name_size.html", |
199
|
|
|
|
|
|
|
$super_html_dir, |
200
|
|
|
|
|
|
|
$prev_file, |
201
|
|
|
|
|
|
|
$next_file, |
202
|
|
|
|
|
|
|
$size, |
203
|
|
|
|
|
|
|
); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Do nothing if max_height or max_width equals 0 |
207
|
|
|
|
|
|
|
$size->get_max_height() && $size->get_max_width() || |
208
|
|
|
|
|
|
|
next; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# Do nothing if the original file is older than the scaled file |
211
|
|
|
|
|
|
|
if ( -f $fs_name_size ) { |
212
|
|
|
|
|
|
|
my $time_orig = ( stat( $self->mk_fs_name() ) )[9]; |
213
|
|
|
|
|
|
|
my $time_scale = ( stat( $fs_name_size ) )[9]; |
214
|
|
|
|
|
|
|
$time_orig < $time_scale && next; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Read the image into ImageMagick |
218
|
|
|
|
|
|
|
my $m = Image::Magick->new(); |
219
|
|
|
|
|
|
|
$m->Read( $self->mk_fs_name() ); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Get width and height and calculate a shrink factor |
222
|
|
|
|
|
|
|
my $width = $m->Get('width'); |
223
|
|
|
|
|
|
|
my $height = $m->Get('height'); |
224
|
|
|
|
|
|
|
my $shrink_w = $size->get_max_width() / $width; |
225
|
|
|
|
|
|
|
my $shrink_h = $size->get_max_height() / $height; |
226
|
|
|
|
|
|
|
my $shrink = $shrink_w < $shrink_h ? $shrink_w : $shrink_h; |
227
|
|
|
|
|
|
|
my $width_new = int( $width * $shrink ); |
228
|
|
|
|
|
|
|
my $height_new = int( $height * $shrink ); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Print verbose message |
231
|
|
|
|
|
|
|
VLGal::Style->instance()->is_verbose() && |
232
|
|
|
|
|
|
|
print STDERR "Scaling file '", |
233
|
|
|
|
|
|
|
$self->mk_fs_name(), |
234
|
|
|
|
|
|
|
"' to $width_new x $height_new\n"; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Make new width and height |
238
|
|
|
|
|
|
|
$m->Scale( |
239
|
|
|
|
|
|
|
'width' => $width_new, |
240
|
|
|
|
|
|
|
'height' => $height_new |
241
|
|
|
|
|
|
|
); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# Write the scaled file |
244
|
|
|
|
|
|
|
$m->Write($fs_name_size); |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |