Extracted NEF Previews have incorrect orientation - any way to enforce?

Started by nemethv, November 17, 2022, 05:54:13 AM

Previous topic - Next topic

nemethv

Hi Phil,

Is there any way to enforce a particular orientation when extracting previews? e.g. this nef file 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

Phil Harvey

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
...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 ($).

nemethv

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. :)

Phil Harvey

You can create a user-defined Composite tag to do exactly what you want.  The BigImage tag in the example config file 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
...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 ($).