ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Viktor Nemeth on November 17, 2022, 05:54:13 AM

Title: Extracted NEF Previews have incorrect orientation - any way to enforce?
Post by: Viktor Nemeth on November 17, 2022, 05:54:13 AM
Hi Phil,

Is there any way to enforce a particular orientation when extracting previews? e.g. this nef file (https://drive.google.com/file/d/1EdDhY28ElsCwGtLzgGVOPxAMoui6e_TR/view?usp=share_link) is a portrait-oriented pic and in Faststone and just about any image viewer it appears okay.
But when I do:
exiftool 20220527_Abbey_Wood__DSC0650.NEF -b -preview:all -w %f.jpg
I end up w a landscape file. If I try to add the -orientation tag it then modifies the nef file but not the jpg output. Is there any way around this?
Thnx
Title: Re: Extracted NEF Previews have incorrect orientation - any way to enforce?
Post by: Phil Harvey on November 17, 2022, 07:08:24 AM
You would have to set the Orientation of the JPG previews in a separate command after they are extracted.

Also, you probably shouldn't be extracting all previews to a single file.  This will just concatenate them.  If you want to extract them all, you should use the capital -W option and add a copy number or something to differentiate the files, like this:

exiftool -b -preview:all -W %f%-c.jpg FILE

Personally, I do this to also add the tag name, and to get the correct extensions in case the previews aren't JPG (not that this is an issue when extracting from NEF files):

exiftool -b -preview:all -W %f_%t%-c.%s FILE

- Phil
Title: Re: Extracted NEF Previews have incorrect orientation - any way to enforce?
Post by: Viktor Nemeth on November 17, 2022, 07:40:53 AM
Thank you, noted
Re: not extract all: In reality I just want one - the problem is that I can't ascertain that any particular file has the preview embedded so in that case the current command (I think) jumps onto the next available thing (like jpgfromraw, it has a different name but i think you know what i mean).
So optimally i'd just need in order of appearance 1) preview, failing that 2) jpgfromraw, failing that 3) anything. :)
Title: Re: Extracted NEF Previews have incorrect orientation - any way to enforce?
Post by: Phil Harvey on November 17, 2022, 07:55:42 AM
You can create a user-defined Composite tag to do exactly what you want.  The BigImage tag in the example config file (https://exiftool.org/config.html) does almost exactly this, but selects the largest preview image.

Your criteria are simpler, and a config file something like this may do what you want (extract the MyPreview tag):

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyPreview => {
            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

- Phil
Title: Re: Extracted NEF Previews have incorrect orientation - any way to enforce?
Post by: Viktor Nemeth on November 17, 2022, 08:11:34 AM
Awesome, that works, thank you!