ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: jchin on July 24, 2018, 05:25:46 PM

Title: extract JPG from RAW and properly rotate orientation ???
Post by: jchin on July 24, 2018, 05:25:46 PM
Is there a way to have exiftool extract the JPEG from RAW and rotate it the proper orientation?
Right now all the extracted JPEG files are landscape (horizontal), including the ones shot portrait (vertical).
Is there a way to use exiftool to rotate them?
I am looking to process a folder full of images.
Thanks in advance.
Title: Re: extract JPG from RAW and properly rotate orientation ???
Post by: Phil Harvey on July 25, 2018, 07:11:47 AM
After extracting the JPEG, copy the Orientation tag to it:

exiftool -tagsfromfile %d%f.RAW -orientation -ext jpg DIR

- Phil
Title: Re: extract JPG from RAW and properly rotate orientation ???
Post by: Pereira on October 29, 2020, 05:46:19 PM
Hi Phil,

First of all thank you very much for writing such a useful piece of software as exiftool. It really has no match!
I am using it to extract thumbnails from raw files like this

exiftool -a -b -ThumbnailImage image.ARW -Orientation | exiftool -tagsfromfile image.ARW -Orientation - > out.jpg

while that works, it's still a bit suboptimal because exiftool has to read the same input file twice, first to extract the thumbnail and a second time to extract the orientation. To me the speed is of essence, because I am extracting small previews for many images on the fly.

I am trying to keep as many things in memory as I can to avoid slow disk operations. Is there a better way of doing it? I am thinking if it is possible to extract the thumbnail with the orientation copied to it already in one pass? I guess what I am asking here might as well be beyond the remit of exiftool, that's ok, I can still do what I want, so I am just curious if there is a better way.

Appreciate your help.
Kind regards
Title: Re: extract JPG from RAW and properly rotate orientation ???
Post by: Phil Harvey on October 31, 2020, 09:16:44 AM
There is also a big performance hit due to the fact that exiftool is launched twice, as well as reading the file twice as you mention.  You solve both of these with this command:

exiftool -config my.config -b -rotatedthumbnail image.ARW > out.jpg

and this my.config file

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        RotatedThumbnail => {
            Require => {
                0 => 'ThumbnailImage',
            },
            Desire => {
                1 => 'Orientation',
            },
            ValueConv => q{
                if (defined $val[1]) {
                    my $et = new Image::ExifTool;
                    $et->SetNewValue('Orientation#', $val[1]);
                    my $rotatedImage;
                    my $success = $et->WriteInfo($val[0], \$rotatedImage);
                    return \$rotatedImage if $success == 1;
                }
                return $val[0];
            },
        },
    },
);
1; #end


- Phil
Title: Re: extract JPG from RAW and properly rotate orientation ???
Post by: Pereira on November 01, 2020, 06:27:50 PM
Wow! This is well beyond something I would have been able to come up Phil, so I appreciate your help. Thank you!
It works like a treat :-)
All the best!
P.
Title: Re: extract JPG from RAW and properly rotate orientation ???
Post by: nemethv on January 11, 2023, 10:03:14 AM
hi Phil,

I'm trying to marry up the above logic with something you gave me at a point in the past.
Originally you gave me a config logic to loop through a variety of preview options until one is found.
This was the reply at the time:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        GTNPreview => {
            Groups => { 2 => 'Preview' },
            Desire => {
                0 => 'PreviewImage',
                1 => 'JpgFromRaw',
                2 => 'MPImage3',
                3 => 'OtherImage',
                4 => 'ThumbnailImage',
            },
            ValueConv => sub {
                my $val = shift;
                my $image;
                foreach $image (@$val) {
                    next unless ref $image eq 'SCALAR';
                    return $image;
                }
                return undef;
            },
        },
    },
);
1;  #end

How do I modify the above to return the appropriately-rotated image instead of non-rotated pls?
I tried

ValueConv => sub {
                my $val = shift;
                my $image;
                foreach $image (@$val) {
                    next unless ref $image eq 'SCALAR';
                    my $et = new Image::ExifTool;
                    $et->SetNewValue('Orientation#', $val[0]);
                    my $rotatedImage;
                    my $success = $et->WriteInfo($val[0], \$rotatedImage);
                    return \$rotatedImage if $success == 1;
                }
                return undef;
            },

... but that's not correct as it's not doing anything.

Thank you.
Title: Re: extract JPG from RAW and properly rotate orientation ???
Post by: Phil Harvey on January 17, 2023, 01:40:29 PM
You need to add Orientation to the Desire'd tags, and use the correct index in the $val[] array when setting the Orientation tag.  Did you add Orientation to the Desire'd tags?

I would assume you would add it with index 5 (ie. after ThumbnailImage in the list), in which case you should do this:

$et->SetNewValue('Orientation#', $val[5]);
- Phil