line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GD::Image::Thumbnail; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
37060
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
2553
|
use POSIX qw(ceil floor); |
|
1
|
|
|
|
|
11786
|
|
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
2021
|
use GD; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub GD::Image::thumbnail { |
11
|
|
|
|
|
|
|
my $gdo = shift; |
12
|
|
|
|
|
|
|
my %thm; |
13
|
|
|
|
|
|
|
my($w,$h) = $gdo->getBounds; |
14
|
|
|
|
|
|
|
if(ref $_[0] eq 'HASH') { |
15
|
|
|
|
|
|
|
delete $thm{nh}; |
16
|
|
|
|
|
|
|
delete $thm{nw}; |
17
|
|
|
|
|
|
|
%thm = %{ shift() }; |
18
|
|
|
|
|
|
|
} else { $thm{side} = shift } |
19
|
|
|
|
|
|
|
my $hori = $w > $h ? 1 : 0; |
20
|
|
|
|
|
|
|
$thm{factor} = 0.20 if !$thm{side} && !$thm{factor} && !$thm{w} && !$thm{h}; |
21
|
|
|
|
|
|
|
if($thm{factor}) { |
22
|
|
|
|
|
|
|
$thm{factor} = 0.20 unless $thm{factor} > 0 && $thm{factor} < 1 && $thm{factor} =~ m/^0\.\d\d$/; |
23
|
|
|
|
|
|
|
if($thm{small}) { |
24
|
|
|
|
|
|
|
$thm{nh} = floor $h * $thm{factor}; |
25
|
|
|
|
|
|
|
$thm{nw} = floor $w * $thm{factor}; |
26
|
|
|
|
|
|
|
} else { |
27
|
|
|
|
|
|
|
$thm{nh} = ceil $h * $thm{factor}; |
28
|
|
|
|
|
|
|
$thm{nw} = ceil $w * $thm{factor}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} else { |
31
|
|
|
|
|
|
|
if($thm{side}) { |
32
|
|
|
|
|
|
|
if($hori) { |
33
|
|
|
|
|
|
|
$thm{nw} = $thm{side} if $thm{small}; |
34
|
|
|
|
|
|
|
$thm{nh} = $thm{side} if !$thm{small}; |
35
|
|
|
|
|
|
|
} else { |
36
|
|
|
|
|
|
|
$thm{nh} = $thm{side} if $thm{small}; |
37
|
|
|
|
|
|
|
$thm{nw} = $thm{side} if !$thm{small}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
if($thm{h} && $thm{w}) { |
41
|
|
|
|
|
|
|
if($hori) { |
42
|
|
|
|
|
|
|
$thm{nw} = $thm{w} if $thm{small}; |
43
|
|
|
|
|
|
|
$thm{nh} = $thm{h} if !$thm{small}; |
44
|
|
|
|
|
|
|
} else { |
45
|
|
|
|
|
|
|
$thm{nh} = $thm{h} if $thm{small}; |
46
|
|
|
|
|
|
|
$thm{nw} = $thm{w} if !$thm{small}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} else { |
49
|
|
|
|
|
|
|
$thm{nh} = $thm{h} if $thm{h}; |
50
|
|
|
|
|
|
|
$thm{nw} = $thm{w} if $thm{w}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
$thm{ratio} = $thm{nw} ? $w/$thm{nw} : $h/$thm{nh}; |
54
|
|
|
|
|
|
|
$thm{nh} = $h/$thm{ratio}; |
55
|
|
|
|
|
|
|
$thm{nw} = $w/$thm{ratio}; |
56
|
|
|
|
|
|
|
if($thm{small}) { |
57
|
|
|
|
|
|
|
$thm{$_} = floor $thm{$_} for('nh','nw'); |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
$thm{$_} = ceil $thm{$_} for('nh','nw'); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
my $tho = new GD::Image($thm{nw},$thm{nh}); |
63
|
|
|
|
|
|
|
if(shift || $thm{resample}) { |
64
|
|
|
|
|
|
|
$tho->copyResampled($gdo,0,0,0,0,$thm{nw},$thm{nh},$w,$h) |
65
|
|
|
|
|
|
|
} else { |
66
|
|
|
|
|
|
|
$tho->copyResized($gdo,0,0,0,0,$thm{nw},$thm{nh},$w,$h) |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
return ($tho,$tho->getBounds) if wantarray; |
69
|
|
|
|
|
|
|
return $tho; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub GD::Image::thumb { shift()->thumbnail(@_); } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |