| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Imager::Filter::ExifOrientation; | 
| 2 | 1 |  |  | 1 |  | 1008 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 3 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 50 |  | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 6 | use Carp; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 69 |  | 
| 7 | 1 |  |  | 1 |  | 496 | use Imager::ExifOrientation; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 8 | 1 |  |  | 1 |  | 10 | use Image::ExifTool (); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 213 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | Imager->register_filter( | 
| 11 |  |  |  |  |  |  | type     => 'exif_orientation', | 
| 12 |  |  |  |  |  |  | callsub  => \&exif_orientation, | 
| 13 |  |  |  |  |  |  | defaults => { | 
| 14 |  |  |  |  |  |  | path        => undef, | 
| 15 |  |  |  |  |  |  | exif        => undef, | 
| 16 |  |  |  |  |  |  | data        => undef, | 
| 17 |  |  |  |  |  |  | orientation => undef, | 
| 18 |  |  |  |  |  |  | }, | 
| 19 |  |  |  |  |  |  | callseq  => ['image'], | 
| 20 |  |  |  |  |  |  | ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub exif_orientation { | 
| 23 | 16 |  |  | 16 | 0 | 12161 | my %args = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 16 |  |  |  |  | 21 | my $orientation; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 16 | 50 |  |  |  | 47 | if ($args{orientation}) { | 
| 28 | 16 |  |  |  |  | 29 | $orientation = $args{orientation}; | 
| 29 |  |  |  |  |  |  | } else { | 
| 30 | 0 |  |  |  |  | 0 | my $exif; | 
| 31 | 0 | 0 |  |  |  | 0 | if ($args{exif}) { | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 32 | 0 |  |  |  |  | 0 | $exif = $args{exif}; | 
| 33 | 0 |  |  |  |  | 0 | $orientation = Imager::ExifOrientation->get_orientation_by_exiftool($exif); | 
| 34 |  |  |  |  |  |  | } elsif ($args{data}) { | 
| 35 | 0 |  |  |  |  | 0 | $exif = Image::ExifTool::ImageInfo(\$args{data}); | 
| 36 | 0 |  |  |  |  | 0 | $orientation = Imager::ExifOrientation->get_orientation_by_exiftool($exif); | 
| 37 |  |  |  |  |  |  | } elsif ($args{path}) { | 
| 38 | 0 |  |  |  |  | 0 | $exif = Image::ExifTool::ImageInfo($args{path}); | 
| 39 | 0 |  |  |  |  | 0 | $orientation = Imager::ExifOrientation->get_orientation_by_exiftool($exif); | 
| 40 |  |  |  |  |  |  | } else { | 
| 41 | 0 |  |  |  |  | 0 | $orientation = $args{imager}->tags(name => 'exif_orientation'); | 
| 42 | 0 | 0 |  |  |  | 0 | return unless defined $orientation; # there is no orientation information | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 16 |  |  |  |  | 126 | my $img = Imager::ExifOrientation->_rotate( | 
| 47 |  |  |  |  |  |  | $args{imager}, $orientation | 
| 48 |  |  |  |  |  |  | ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 16 |  |  |  |  | 670 | $args{imager}->{IMG} = $img->{IMG}; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | 1; | 
| 54 |  |  |  |  |  |  | __END__ |