blib/lib/Image/Magick/Stencilize.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 62 CC 2 SCAR 12.8
CC
2
Cov
0%
Stencilize
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 package Image::Magick::Stencilize;
2 use strict;
3 use vars qw($VERSION);
4 $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)/g;
5  
6 #use Exporter;
7 #use vars qw(@ISA @EXPORT);
8 #@ISA = qw/Exporter/;
9 #@EXPORT = 'Stencilize';
10 #use Smart::Comments '###';
11  
12 #Imaeg
13  
14 #$Image::Magick::
15  
16 # in the tradition of image magick names:
17  
18 no strict 'refs';
19 *Image::Magick::Stencilize = \&Stencilize;
20  
21 sub Stencilize {
22 my $self = shift; # image magick object
23 my $threshold = shift;
24 $threshold ||= 40;
25 my $blur_percentage = shift;
26 $blur_percentage||= 4;
27 $blur_percentage > 0 and $blur_percentage < 100 or die('blur percentage must be over 0 and under 100');
28
29 $blur_percentage = ($blur_percentage / 100 );
30 ### $blur_percentage
31  
32 if ($threshold > 75 or $threshold < 15){
33 warn("threshold is set at $threshold, that will likely produce no results, should be between 15 and 75");
34 }
35 $threshold = ( $threshold * 1000 );
36
37 # i guess ideally return same size
38  
39 # resize by 50%
40 my($h,$w)=$self->Get('height','width');
41 my($_h,$_w) = (int ($h * 2), int ($w * 2));
42  
43
44  
45
46  
47 my $blur = int($blur_percentage * ((($_h + $_w)/2)/3) );
48 ### $blur
49 $blur||=1;
50  
51 $self->Resize( geometry => $_w.'x'.$_h,);#blur => 1.3);#blur => 1.2 );
52 $self->Blur( geometry => $blur.'x'.$blur );
53 $self->Set( colorspace => 'rgb' );
54 #$self->Equalize;
55  
56
57 $self->Threshold( threshold => $threshold );
58  
59 #$self->Set( colorspace => 'gray' );
60  
61 #$self->Normalize;
62 #$self->Negate;
63 #$self->Threshold( threshold => 0 );
64 #$self->Negate;
65  
66
67 $self->Resize( geometry => $w.'x'.$h, blur => 1);
68  
69 return;
70 }
71  
72  
73  
74 1;
75  
76  
77 __END__