| 1 | package App::CopyrightImage; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use File::Find::Rule; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Image::ExifTool qw(:Public); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | our @EXPORT = qw(imgcopyright); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | our $VERSION = '1.01'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | ▶ | sub imgcopyright { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
imgcopyright: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | my (%data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | die "need to supply the 'image' argument!\n" if ! $data{src}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | if (! $data{name} && (! $data{check} && ! $data{remove})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$data{"name"} or ($data{"check"} or $data{"remove"})
$data{"check"} or $data{"remove"}
MC/DC100%3/3
$data{"name"} or ($data{"check"} or $data{"remove"})
$data{"name"}
$data{"check"}
$data{"remove"}
Truth table100%4/4
A or B or C
A= $data{"name"}B= $data{"check"}C= $data{"remove"}
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | die "need to supply the 'name' argument\n"; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | $data{year} = (localtime(time))[5] + 1900; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | if ($data{dst} && -d $data{dst}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$data{"dst"} and -d $data{"dst"}
MC/DC0%0/2
$data{"dst"} and -d $data{"dst"}
$data{"dst"}
-d $data{"dst"}
Truth table66%2/3
A and B
A= $data{"dst"}B= -d $data{"dst"}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $data{basename} = $data{dst}; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | elsif (-d $data{src}) | ||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | $data{basename} = $data{src}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | $data{basename} = dirname $data{src}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | if (-d $data{src}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | @{ $data{images} } = File::Find::Rule->file() | |||||||||||||||||||||||||||||||||||||||||
| 39 | ->name('*.jpg', '*.jpeg') | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ->maxdepth(1) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ->in($data{src}); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | push @{ $data{images} }, $data{src}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | if ($data{check}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | return _check(\%data); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | _exif(\%data); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | sub _exif { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exif: called CC=14 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | my $dst = $data->{dst} | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ? $data->{dst} | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | : "$data->{basename}/ci"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | if (! -d $dst){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | ▶ | mkdir $dst | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | or die "can't create the destination image directory $dst!: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | my $et = Image::ExifTool->new; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | my %errors; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | for my $img (@{ $data->{images} }){ | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # original | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | $et->ExtractInfo($img); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | ▶ | if ($data->{remove}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | $et->SetNewValue('Copyright', ''); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $et->SetNewValue('Creator', ''); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $et->WriteInfo($img, "$img.tmp"); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | move "$img.tmp", $img; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | my $cp = $et->GetValue('Copyright'); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | my $cr = $et->GetValue('Creator'); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | if (! $data->{force} && ($cp || $cr)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $data->{"force"} and $cp || $cr
$cp or $cr
MC/DC66%2/3
not $data->{"force"} and $cp || $cr
not $data->{"force"}
$cp
$cr
Truth table75%3/4
not(A) and B or C
A= not $data->{"force"}B= $cpC= $cr
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | my $set = "Copyright is already set;" if $cp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | $set .= " Creator is already set;" if $cr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | $errors{$img} = $set; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | $et->SetNewValue('Copyright', "Copyright (C) $data->{year} by $data->{name}"); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | my $creator_string = $data->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | $creator_string .= " ($data->{email})" if $data->{email}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | $et->SetNewValue('Creator', $creator_string); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | my $ci_img = (fileparse($img))[0]; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | $ci_img = "$dst/ci_$ci_img"; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # write out the new image | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | $et->WriteInfo($img, $ci_img); | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # updated | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | $et->ExtractInfo($ci_img); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | ▶ | $errors{$img} = "failed to add Copyright; " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | if ! $et->GetValue('Copyright'); | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | $errors{$img} .= "failed to add Creator" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | if ! $et->GetValue('Creator'); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | return %errors; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | sub _check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | my $et = Image::ExifTool->new; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | for (@{ $data->{images} }){ | |||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | $et->ExtractInfo($_); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | my $cp = $et->GetValue('Copyright'); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | my $cr = $et->GetValue('Creator'); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | my $err_str; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | ▶ | $err_str .= " missing Copyright; " if ! $cp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | $err_str .= " missing Creator; " if ! $cr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | ▶ | print "$_: $err_str\n" if $err_str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||||||||||||||||