line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::SpriteBuilder::ImageDriver::Common; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
CSS::SpriteBuilder::Image::Common - Abstract class for image manipulation |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $image = SpriteBuilder::ImageDriver::->new(); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$image->read('image.png'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$image->extent( $image->width() * 2, $image->height() * 2); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$image->write('image2.png'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 new |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $image = SpriteBuilder::ImageDriver::->new(); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Creates a new blank image. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=back |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 driver |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Returns a driver name (ImageMagick, GD or undef). |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=back |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 width |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Returns a width of image. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=back |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 height |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Returns a height of image. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=back |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 is_blank |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns '1' when image is blank. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=back |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 reset([]) |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Make a blank image. |
54
|
|
|
|
|
|
|
When B parameter is specified than assign the initial value as B. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 set_transparent_color() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$image->set_transparent_color('white'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Set transparent color. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=back |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 set_quality(<0..100>) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Set image qualit (for JPEG only). |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=back |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 read() |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Reads an image from a file. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 write() |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Writes the image to a file. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 extent(, ) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Extent image to B x B. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=back |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 composite(, , ) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Composite image, specified by B parameter, onto source image. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
158
|
|
99
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
145
|
|
100
|
4
|
|
|
4
|
|
20
|
use Scalar::Util qw(blessed); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1954
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub new { |
103
|
6
|
|
|
6
|
1
|
52
|
my ($class, @args) = @_; |
104
|
|
|
|
|
|
|
|
105
|
6
|
|
|
|
|
72
|
my $self = bless { |
106
|
|
|
|
|
|
|
_image => undef, |
107
|
|
|
|
|
|
|
_quality => undef, |
108
|
|
|
|
|
|
|
@args, |
109
|
|
|
|
|
|
|
}, $class; |
110
|
|
|
|
|
|
|
|
111
|
6
|
|
|
|
|
43
|
$self->reset(); |
112
|
|
|
|
|
|
|
|
113
|
6
|
|
|
|
|
25
|
return $self; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
1
|
0
|
sub driver { undef } |
117
|
0
|
|
|
0
|
1
|
0
|
sub width { 0 } |
118
|
0
|
|
|
0
|
1
|
0
|
sub height { 0 } |
119
|
9
|
100
|
|
9
|
1
|
33
|
sub is_blank { $_[0]->width() ? 0 : 1 } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub reset { |
122
|
0
|
|
|
0
|
1
|
0
|
my ($self, $image) = @_; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Nothing |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
0
|
return; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub set_transparent_color { |
130
|
0
|
|
|
0
|
1
|
0
|
my ($self, $color) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Nothing |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub set_quality { |
138
|
3
|
|
|
3
|
1
|
6
|
my ($self, $quality) = @_; |
139
|
|
|
|
|
|
|
|
140
|
3
|
|
|
|
|
5
|
$self->{_quality} = $quality; |
141
|
|
|
|
|
|
|
|
142
|
3
|
|
|
|
|
8
|
return; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub read { |
146
|
0
|
|
|
0
|
1
|
|
my ($self, $filename) = @_; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
die "Not implemented"; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub write { |
152
|
0
|
|
|
0
|
1
|
|
my ($self, $filename) = @_; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
die "Not implemented"; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub extent { |
158
|
0
|
|
|
0
|
1
|
|
my ($self, $width, $height) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
die "Not implemented"; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub composite { |
164
|
0
|
|
|
0
|
1
|
|
my ($self, $image, $x, $y) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
die "Not implemented"; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |