line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::FormValidator::Filters::ImgData; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1612
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
6
|
1
|
|
|
1
|
|
4
|
use base qw(Exporter); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
81
|
|
7
|
1
|
|
|
1
|
|
5
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@EXPORT = qw( |
10
|
|
|
|
|
|
|
filter_resize |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use version; our $VERSION = qv('0.0.3'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Module implementation here |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub filter_resize { |
18
|
|
|
|
|
|
|
my $width = shift; |
19
|
|
|
|
|
|
|
my $height = shift; |
20
|
|
|
|
|
|
|
my $type = shift || 'jpeg'; |
21
|
|
|
|
|
|
|
return sub { |
22
|
1
|
|
|
1
|
|
548
|
use GD; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
GD::Image->trueColor( 1 ); |
24
|
|
|
|
|
|
|
my $data = shift; |
25
|
|
|
|
|
|
|
my $image = GD::Image->new($data); |
26
|
|
|
|
|
|
|
my $old_width = ($image->getBounds)[0]; |
27
|
|
|
|
|
|
|
my $old_height = ($image->getBounds)[1]; |
28
|
|
|
|
|
|
|
my $k_h = $height / $old_height; |
29
|
|
|
|
|
|
|
my $k_w = $width / $old_width; |
30
|
|
|
|
|
|
|
my $k = ($k_h < $k_w ? $k_h : $k_w); |
31
|
|
|
|
|
|
|
my $new_height = int($old_height * $k); |
32
|
|
|
|
|
|
|
my $new_width = int($old_width * $k); |
33
|
|
|
|
|
|
|
my $new_image = GD::Image->new($new_width, $new_height); |
34
|
|
|
|
|
|
|
$new_image->copyResampled($image, |
35
|
|
|
|
|
|
|
0, 0, # (destX, destY) |
36
|
|
|
|
|
|
|
0, 0, # (srcX, srxY ) |
37
|
|
|
|
|
|
|
$new_width, $new_height, # (destX, destY) |
38
|
|
|
|
|
|
|
$old_width, $old_height |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
return $new_image->$type(); |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
45
|
|
|
|
|
|
|
__END__ |