File Coverage

blib/lib/Image/Magick/Brand.pm
Criterion Covered Total %
statement 9 57 15.7
branch 0 20 0.0
condition 0 12 0.0
subroutine 3 6 50.0
pod n/a
total 12 95 12.6


line stmt bran cond sub pod time code
1             package Image::Magick::Brand;
2              
3 1     1   67909 use strict;
  1         2  
  1         44  
4 1     1   5 use warnings;
  1         3  
  1         32  
5 1     1   5 use Carp;
  1         5  
  1         2784  
6              
7             require Image::Magick;
8              
9             our $VERSION = '0.01';
10              
11             sub new {
12 0     0     my $class = shift;
13 0           my $self = bless {}, $class;
14             }
15              
16             sub debug {
17 0     0     my $self = shift;
18 0           $self->{debug} = shift;
19             }
20              
21             sub brand {
22 0     0     my ($self, %args) = @_;
23            
24             # Required Parameters
25 0           my $source = $args{source};
26 0           my $target = $args{target};
27 0           my $output = $args{output};
28            
29             # Optional Parameters
30 0   0       my $gravity = $args{gravity} || 'SouthWest';
31 0   0       my $composite = $args{composite} || 'over';
32 0   0       my $format = $args{format} || 'jpg';
33 0   0       my $quality = $args{quality} || 100;
34              
35             # Error Checking
36 0 0         if( !$source ){
37 0           carp "No source image specified";
38 0           return undef;
39             }
40            
41 0 0         if( !$target ){
42 0           carp "No target image specified.";
43 0           return undef;
44             }
45              
46 0 0         if( !$output ){
47 0           carp "No output image specified.";
48 0           return undef;
49             }
50              
51             # Debug Output
52 0 0         if( $self->{debug} ){
53 0           warn "Source : $source\n";
54 0           warn "Target : $target\n";
55 0           warn "Output : $output\n";
56 0           warn "Gravity : $gravity\n";
57 0           warn "Composite : $composite\n";
58 0           warn "Quality : $quality\n";
59 0           warn "Format : $format\n";
60             }
61            
62 0           eval {
63              
64 0           my $im_s = new Image::Magick;
65 0           my $im_t = new Image::Magick;
66              
67 0           my $err;
68            
69 0 0 0       open(IMAGE,"<$source") or carp "Could not open source image: $source ($!)" and return undef;
70 0           $err = $im_s->Read(file=>\*IMAGE);
71 0 0         die $err if $err;
72 0           close(IMAGE);
73              
74 0 0 0       open(IMAGE,"<$target") or carp "Could not open target image: $target ($!)" and return undef;
75 0           $err = $im_t->Read(file=>\*IMAGE);
76 0 0         die $err if $err;
77 0           close(IMAGE);
78              
79 0           $im_s->Set( quality => $quality );
80 0           $im_t->Set( quality => $quality );
81              
82 0           $im_t->Composite( image => $im_s,
83             composite => 'over',
84             gravity => $gravity );
85            
86 0           $im_t->Write("$format:$output");
87             };
88              
89 0 0         if( $@ ){
90 0 0         warn $@ and return undef;
91             }
92            
93 0           return 1;
94             }
95              
96             1;
97             __END__