line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Selenium::Screenshot::CanPad; |
2
|
|
|
|
|
|
|
$Selenium::Screenshot::CanPad::VERSION = '0.08'; |
3
|
2
|
|
|
2
|
|
12556
|
use Scalar::Util qw/blessed/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
100
|
|
4
|
2
|
|
|
2
|
|
11
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Provides subs for coercing two images to the exact width and height |
6
|
2
|
|
|
2
|
|
13
|
use Moo::Role; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
11
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub coerce_image_size { |
11
|
1
|
|
|
1
|
1
|
10444
|
my ($self, $image1, $image2) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
2
|
foreach ( $image1, $image2 ) { |
14
|
2
|
50
|
33
|
|
|
20
|
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
|
|
|
|
2
|
if ( _is_smaller( $image1, $coerce_dims ) ) { |
20
|
1
|
|
|
|
|
10
|
$image1 = _pad_image( $image1, $coerce_dims ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
2
|
if ( _is_smaller( $image2, $coerce_dims ) ) { |
24
|
1
|
|
|
|
|
19
|
$image2 = _pad_image( $image2, $coerce_dims ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
3
|
return ( $image1, $image2 ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub cmp_image_dims { |
32
|
2
|
|
|
2
|
1
|
1610
|
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
|
|
558
|
my ($image1, $image2) = @_; |
45
|
|
|
|
|
|
|
|
46
|
2
|
50
|
|
|
|
13
|
my $max_width = $image1->getwidth >= $image2->getwidth |
47
|
|
|
|
|
|
|
? $image1->getwidth |
48
|
|
|
|
|
|
|
: $image2->getwidth; |
49
|
|
|
|
|
|
|
|
50
|
2
|
50
|
|
|
|
43
|
my $max_height = $image1->getheight >= $image2->getheight |
51
|
|
|
|
|
|
|
? $image1->getheight |
52
|
|
|
|
|
|
|
: $image2->getheight; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
34
|
my $dimensions = { |
55
|
|
|
|
|
|
|
width => $max_width, |
56
|
|
|
|
|
|
|
height => $max_height |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
2
|
return $dimensions |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _is_smaller { |
63
|
4
|
|
|
4
|
|
1267
|
my ($image, $dimensions) = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $image->getwidth < $dimensions->{width} || |
66
|
4
|
|
100
|
|
|
8
|
$image->getheight < $dimensions->{height}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _pad_image { |
70
|
3
|
|
|
3
|
|
542
|
my ($image, $dimensions) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $padded_image = Imager->new( |
73
|
|
|
|
|
|
|
xsize => $dimensions->{width}, |
74
|
|
|
|
|
|
|
ysize => $dimensions->{height}, |
75
|
3
|
|
|
|
|
7
|
channels => $image->getchannels |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
89
|
$padded_image->paste( |
79
|
|
|
|
|
|
|
left => 0, |
80
|
|
|
|
|
|
|
top => 0, |
81
|
|
|
|
|
|
|
img => $image |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
92
|
return $padded_image; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |