| 1 | package Image::Magick::Thumbnail::Simple; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | our $VERSION = '0.12'; | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | require Image::Magick; | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | my $error = q{}; | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 14 | # Module declaration | ||||||||||||||||||||||||||||||||
| 15 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 17 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||
| 18 | 0 | my %argv = @_; | |||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $class = ref( $proto ) || $proto; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||
| 20 | my $self = { | ||||||||||||||||||||||||||||||||
| 21 | SIZE => $argv{'size'} || undef, | ||||||||||||||||||||||||||||||||
| 22 | BLUR => $argv{'blur'} || 1, | ||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | QUALITY => $argv{'quality'} || undef, | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$argv{'size'} || undef
$argv{'blur'} || 1
$argv{'quality'} || undef
MC/DC0%0/1
$argv{'size'} || undef
$argv{'size'}
MC/DC0%0/1
$argv{'blur'} || 1
$argv{'blur'}
MC/DC0%0/1
$argv{'quality'} || undef
$argv{'quality'}
Truth table0%0/2
A
A= $argv{'size'}
Truth table0%0/2
A
A= $argv{'blur'}
Truth table0%0/2
A
A= $argv{'quality'}
| |||||||||||||||||||||||||||||||||
| 24 | WIDTH => undef, | ||||||||||||||||||||||||||||||||
| 25 | HEIGHT => undef, | ||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||
| 27 | 0 | bless( $self, $class ); | |||||||||||||||||||||||||||||||
| 28 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 31 | # error | ||||||||||||||||||||||||||||||||
| 32 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 35 | 0 | return $error; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 38 | # size | ||||||||||||||||||||||||||||||||
| 39 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub size { | ||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if( @_ ){ $self -> {SIZE} = shift } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 0 | return $self -> {SIZE}; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 46 | # blur | ||||||||||||||||||||||||||||||||
| 47 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub blur { | ||||||||||||||||||||||||||||||
|
Subroutine
blur: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if( @_ ){ $self -> {BLUR} = shift } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 0 | return $self -> {BLUR}; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 54 | # quality | ||||||||||||||||||||||||||||||||
| 55 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub quality { | ||||||||||||||||||||||||||||||
|
Subroutine
quality: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if( @_ ){ $self -> {QUALITY} = shift } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | return $self -> {QUALITY}; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 62 | # width | ||||||||||||||||||||||||||||||||
| 63 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub width { | ||||||||||||||||||||||||||||||
|
Subroutine
width: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 66 | 0 | return $self -> {WIDTH}; | |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 69 | # height | ||||||||||||||||||||||||||||||||
| 70 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub height { | ||||||||||||||||||||||||||||||
|
Subroutine
height: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 73 | 0 | return $self -> {HEIGHT}; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 76 | # thumbnail | ||||||||||||||||||||||||||||||||
| 77 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub thumbnail { | ||||||||||||||||||||||||||||||
|
Subroutine
thumbnail: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 80 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | my $input = $args{'input'}; | |||||||||||||||||||||||||||||||
| 83 | 0 | my $output = $args{'output'}; | |||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $size = $args{'size'} || $self -> {SIZE}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'size'} || $self->{'SIZE'}
MC/DC0%0/2
$args{'size'} || $self->{'SIZE'}
$args{'size'}
$self->{'SIZE'}
Truth table0%0/3
A || B
A= $args{'size'}B= $self->{'SIZE'}
| |||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $blur = $args{'blur'} || $self -> {BLUR}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'blur'} || $self->{'BLUR'}
MC/DC0%0/2
$args{'blur'} || $self->{'BLUR'}
$args{'blur'}
$self->{'BLUR'}
Truth table0%0/3
A || B
A= $args{'blur'}B= $self->{'BLUR'}
| |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my $quality = $args{'quality'} || $self -> {QUALITY}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'quality'} || $self->{'QUALITY'}
MC/DC0%0/2
$args{'quality'} || $self->{'QUALITY'}
$args{'quality'}
$self->{'QUALITY'}
Truth table0%0/3
A || B
A= $args{'quality'}B= $self->{'QUALITY'}
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | #input | ||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if( !$input ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 0 | $error = 'No input specified'; | |||||||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | # output | ||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if( !$output ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 0 | $error = 'No output specified'; | |||||||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | # size | ||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if( !$size ){ | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 102 | 0 | $error = 'No size or scale specified'; | |||||||||||||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | elsif( $size <= 0 ){ | ||||||||||||||||||||||||||||||||
| 106 | 0 | $error = 'Invalid width'; | |||||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | my $image = new Image::Magick; | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | $image -> Read( $input ); | |||||||||||||||||||||||||||||||
| 113 | 0 | my( $width, $height ) = $image -> Ping( $input ); | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | # horizonal | ||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if( $width > $height ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 0 | $self -> {HEIGHT} = int( $height * ( $size / $width ) ); | |||||||||||||||||||||||||||||||
| 118 | 0 | $self -> {WIDTH} = $size; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | # vertical | ||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||
| 123 | 0 | $self -> {WIDTH} = int( $width * ( $size / $height ) ); | |||||||||||||||||||||||||||||||
| 124 | 0 | $self -> {HEIGHT} = $size; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $image -> Set( quality => $quality ) if $quality; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | $image -> Resize( | ||||||||||||||||||||||||||||||||
| 129 | width => $self -> {WIDTH}, | ||||||||||||||||||||||||||||||||
| 130 | height => $self -> {HEIGHT}, | ||||||||||||||||||||||||||||||||
| 131 | 0 | blur => $blur, | |||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||
| 133 | 0 | $image -> Write( $output ); | |||||||||||||||||||||||||||||||
| 134 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | # Preloaded methods go here. | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 1; | ||||||||||||||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||||||||||||||