line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Selenium::Screenshot::CanPad; |
2
|
|
|
|
|
|
|
$Selenium::Screenshot::CanPad::VERSION = '0.06'; |
3
|
2
|
|
|
2
|
|
15267
|
use Scalar::Util qw/blessed/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
140
|
|
4
|
2
|
|
|
2
|
|
12
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
109
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Provides subs for coercing two images to the exact width and height |
6
|
2
|
|
|
2
|
|
24
|
use Moo::Role; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub coerce_image_size { |
11
|
1
|
|
|
1
|
1
|
12212
|
my ($self, $image1, $image2) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
4
|
foreach ( $image1, $image2 ) { |
14
|
2
|
50
|
33
|
|
|
22
|
croak 'Expected two Imager objects' unless blessed $_ && $_->isa('Imager'); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
3
|
my $coerce_dims = _get_largest_dimensions( $image1, $image2 ); |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
3
|
if ( _is_smaller( $image1, $coerce_dims ) ) { |
20
|
1
|
|
|
|
|
14
|
$image1 = _pad_image( $image1, $coerce_dims ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
2
|
if ( _is_smaller( $image2, $coerce_dims ) ) { |
24
|
1
|
|
|
|
|
23
|
$image2 = _pad_image( $image2, $coerce_dims ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
5
|
return ( $image1, $image2 ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub cmp_image_dims { |
32
|
2
|
|
|
2
|
1
|
1859
|
my ($self, $image1, $image2) = @_; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
3
|
foreach ( $image1, $image2 ) { |
35
|
4
|
50
|
33
|
|
|
24
|
croak 'Expected two Imager objects' |
36
|
|
|
|
|
|
|
unless blessed $_ && $_->isa('Imager'); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
66
|
|
|
7
|
return $image1->getheight == $image2->getheight && |
40
|
|
|
|
|
|
|
$image1->getwidth == $image2->getwidth; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _get_largest_dimensions { |
44
|
2
|
|
|
2
|
|
991
|
my ($image1, $image2) = @_; |
45
|
|
|
|
|
|
|
|
46
|
2
|
50
|
|
|
|
8
|
my $max_width = $image1->getwidth >= $image2->getwidth |
47
|
|
|
|
|
|
|
? $image1->getwidth |
48
|
|
|
|
|
|
|
: $image2->getwidth; |
49
|
|
|
|
|
|
|
|
50
|
2
|
50
|
|
|
|
49
|
my $max_height = $image1->getheight >= $image2->getheight |
51
|
|
|
|
|
|
|
? $image1->getheight |
52
|
|
|
|
|
|
|
: $image2->getheight; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
36
|
my $dimensions = { |
55
|
|
|
|
|
|
|
width => $max_width, |
56
|
|
|
|
|
|
|
height => $max_height |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
4
|
return $dimensions |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _is_smaller { |
63
|
4
|
|
|
4
|
|
2519
|
my ($image, $dimensions) = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $image->getwidth < $dimensions->{width} || |
66
|
4
|
|
100
|
|
|
13
|
$image->getheight < $dimensions->{height}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _pad_image { |
70
|
3
|
|
|
3
|
|
1172
|
my ($image, $dimensions) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $padded_image = Imager->new( |
73
|
|
|
|
|
|
|
xsize => $dimensions->{width}, |
74
|
|
|
|
|
|
|
ysize => $dimensions->{height}, |
75
|
3
|
|
|
|
|
13
|
channels => $image->getchannels |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
137
|
$padded_image->paste( |
79
|
|
|
|
|
|
|
left => 0, |
80
|
|
|
|
|
|
|
top => 0, |
81
|
|
|
|
|
|
|
img => $image |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
150
|
return $padded_image; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |