line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::SpriteBuilder::ImageDriver::ImageMagick; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
CSS::SpriteBuilder::ImageDriver::ImageMagick - Class for image manipulation using Image::Magick module. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
39
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
155
|
|
10
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
218
|
|
11
|
4
|
|
|
4
|
|
2150
|
use Image::Magick; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use base 'CSS::SpriteBuilder::ImageDriver::Common'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub driver { 'ImageMagick' } |
15
|
|
|
|
|
|
|
sub width { $_[0]->{_image}->Get('width') || 0 } |
16
|
|
|
|
|
|
|
sub height { $_[0]->{_image}->Get('height') || 0 } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub reset { |
19
|
|
|
|
|
|
|
my ($self, $image) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$self->{_image} = $image ? $image->{_image}->Clone() : Image::Magick->new() |
22
|
|
|
|
|
|
|
or die "Failed to create image due: $!"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub read { |
28
|
|
|
|
|
|
|
my ($self, $filename) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $error = $self->{_image}->Read($filename); |
31
|
|
|
|
|
|
|
die "Failed to read image from '$filename' due: $error" if $error; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->{_image}->Set(type => 'TruecolorMatte'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub write { |
39
|
|
|
|
|
|
|
my ($self, $filename) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if ( $self->{_quality} && $filename =~ /\.jpg$/i ) { |
42
|
|
|
|
|
|
|
$self->{_image}->Set( quality => $self->{_quality} ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $error = $self->{_image}->Write($filename); |
46
|
|
|
|
|
|
|
die "Failed to write image to '$filename' due: $error" if $error; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub set_transparent_color { |
52
|
|
|
|
|
|
|
my ($self, $color) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->{_image}->Transparent(color => $color); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub extent { |
60
|
|
|
|
|
|
|
my ($self, $width, $height) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->{_image}->Extent( |
63
|
|
|
|
|
|
|
width => $width, |
64
|
|
|
|
|
|
|
height => $height, |
65
|
|
|
|
|
|
|
background => 'none', |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub composite { |
72
|
|
|
|
|
|
|
my ($self, $image, $x, $y) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->{_image}->Composite( |
75
|
|
|
|
|
|
|
image => $image->{_image}, |
76
|
|
|
|
|
|
|
x => $x, |
77
|
|
|
|
|
|
|
y => $y, |
78
|
|
|
|
|
|
|
compose => "over", |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |