extract JPG from RAW and properly rotate orientation ???

Started by jchin, July 24, 2018, 05:25:46 PM

Previous topic - Next topic

jchin

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.

Phil Harvey

After extracting the JPEG, copy the Orientation tag to it:

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

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Pereira

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Pereira

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.

nemethv

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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).