blib/lib/Image/JpegTran/AutoRotate.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 20 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 77 CC 3 SCAR 16.1
CC
3
Cov
0%
auto_rotate
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.0
1 package Image::JpegTran::AutoRotate;
2 use 5.006;
3 use strict;
4 use Exporter ();
5 use Image::ExifTool ();
6 use Image::JpegTran qw(jpegtran);
7 use File::Temp qw(:POSIX);
8 use File::Copy qw(copy);
9  
10 our $VERSION = '0.01';
11 our @ISA = qw(Exporter);
12 our @EXPORT = qw(auto_rotate);
13  
14 sub auto_rotate {
15 my ($from, $to) = @_;
16 -s $from or return;
17 my $exifTool = Image::ExifTool->new;
18 $exifTool->ExtractInfo($from) or return;
19 my $orientation = $exifTool->GetValue(Orientation => 'Raw') or return;
20 my %TransformMap = (
21 2 => [flip => 'horizontal'],
22 3 => [rotate => 180],
23 4 => [flip => 'vertical'],
24 5 => ['transpose'],
25 6 => [rotate => 90],
26 7 => ['transverse'],
27 8 => [rotate => 270]
28 );
29 my $transform = $TransformMap{$orientation} or return -1;
30 my $tmp;
31 $tmp = tmpnam() unless defined $to;
32 jpegtran($from => ($tmp || $to), @$transform);
33 if ($tmp and -s $tmp) {
34 $to = $from;
35 copy($tmp => $to) or return;
36 unlink $tmp or return;
37 }
38 $exifTool->ExtractInfo($to) or return;
39 $exifTool->SetNewValue(Orientation => 'Horizontal (normal)');
40 $exifTool->WriteInfo($to);
41 return 1;
42 }
43  
44 __END__