line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::RatioResize; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
134406
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
422
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Math::RatioResize - Work out new dimensions for an image (or just a rectangle) when restricted in one dimension. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.03 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Given a box dimensions (width and height), and a max width or height, return back the resized dimensions whilst maintaining the aspect-ratio. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Math::RatioResize; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ( $w, $h ) = Math::RatioResize->resize( w => 360, h => 240, max_w => 100 ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$w == 100 |
29
|
|
|
|
|
|
|
$h == 66.66 # 240 * ( 100 / 360 ) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 Class Methods |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head3 resize |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
As above. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub resize |
42
|
|
|
|
|
|
|
{ |
43
|
2
|
|
|
2
|
1
|
238
|
my ( $self, %args ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
3
|
my $w = $args{ w }; |
46
|
2
|
|
|
|
|
4
|
my $h = $args{ h }; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
3
|
my $max_w = $args{ max_w }; |
49
|
2
|
|
|
|
|
4
|
my $max_h = $args{ max_h }; |
50
|
|
|
|
|
|
|
|
51
|
2
|
100
|
66
|
|
|
9
|
if ( $max_w && $w > $max_w ) |
52
|
|
|
|
|
|
|
{ |
53
|
1
|
|
|
|
|
4
|
$h = $h * ( $max_w / $w ); |
54
|
1
|
|
|
|
|
2
|
$w = $max_w; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
2
|
100
|
66
|
|
|
11
|
if ( $max_h && $h > $max_h ) |
58
|
|
|
|
|
|
|
{ |
59
|
1
|
|
|
|
|
3
|
$w = $w * ( $max_h / $h ); |
60
|
1
|
|
|
|
|
2
|
$h = $max_h; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
15
|
return $w, $h; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Rob Brown, C<< >> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 BUGS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
73
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you will |
74
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SUPPORT |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
perldoc Math::RatioResize |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
You can also look for information at: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 4 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
L |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * CPAN Ratings |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * Search CPAN |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright 2013 Rob Brown. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
110
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
111
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |