Get image orientation from variable

Started by fincire, December 23, 2020, 03:02:08 PM

Previous topic - Next topic

fincire

I'm trying to extract an image's orientation based on what I think is a fairly simple formula:

{File.Width|NumComp:gt,{File.Height},Landscape} {File.Height|NumComp:gt,{File.Width},Portrait} {File.Width|NumComp:eq,{File.Height},Square}

VarToy reports that it works, about 85% of the time. But sometimes, Portrait images are listed as Landscape and vice versa.

Is there something wrong with my syntax?

While I know I can use filter patterns to sort for this, having it extracted this way would help my workflow since I often work with images that are lacking basic metadata due to corruption or mishandling. {File.MD.XMP::tiff\Orientation\Orientation\0} and other standard orientation metadata tags are blank with these images.

Thanks in advance!

Mario

Probable just the missing cast:
{File.Width|cast:int;numcomp...}

Remember that variables are meant to be used for display purposes and that they always apply the number formatting (and date/time formatting) configured for the current Windows user.
numcomp cannot deal with text like "1,920" or "1.920" (depending on your country). It needs to see a proper number. cast:int makes sure of that.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

fincire

Thank you, Mario! I changed my formula to this:

{File.Width|numformat:int,;NumComp:gt,{File.Height|numformat:int,},Landscape,;NumComp:lt,{File.Height|numformat:int,},Portrait,;NumComp:eq,{File.Height|numformat:int,},Square,}

And it seems to be working perfectly.

I'm still learning how to properly nest complex instructions. My next challenge is to build on the formula above and get it to automatically sort images first by this manual orientation, and then based on minimum dimensions.

So if an image is Landscape (i.e., File.Width>File.Height), I'd like to add more information, such as this:

Landscape
-- Width >900px AND Height >600px
--(All other Landscape images)
Portrait
-- Width >460px AND Height >720px
--(All other Portrait images)

etc. etc.

This would help me cull out images that are too small and keep things tidy for quick sorting. I know I could accomplish this with Filter patterns, but I'd like to set it up using a formula so I can create data-driven or formula-driven categories to sort dynamically. It would help since part of my job is to quickly sift through folders with thousands of images, many of which have bad or missing basic metadata (like orientation).

Does this make sense? Or am I making it unnecessarily complicated?

sinus

Quote from: fincire on December 24, 2020, 08:22:31 AM
Thank you, Mario! I changed my formula to this:

{File.Width|numformat:int,;NumComp:gt,{File.Height|numformat:int,},Landscape,;NumComp:lt,{File.Height|numformat:int,},Portrait,;NumComp:eq,{File.Height|numformat:int,},Square,}

And it seems to be working perfectly.

Hmm, I have a shorter variable, and without cast:int ...
{File.Width|numcomp:gt,{File.Height},Q,H}

I have to check that.  8)

But I made a short test with your variable and mine (with VarToy) and the result is always the same with both variables. But ok, I have only tested say 50 images.


Ah, just seen, you have also a square, what I have not ...
Best wishes from Switzerland! :-)
Markus

Mario

QuoteThis would help me cull out images that are too small and keep things tidy for quick sorting.

Why not just using an Orientation and Dimension filter in the Filter Panel?
Create it once, save it and then just enable it when needed.

You cannot sort by variables. You can sort by width, height, orientation, pixel count, file size and arbitrary metadata tags. No variables.
See Sort Profiles for more info.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

fincire

That's what I have been doing. The Filter panel works fine, I just find it a little less streamlined due to the structure of my workflow and the sorting process I have to follow...


  • Go to a folder I need to sort (often 100-5000 images
  • Activate a saved filter - "Landscape, <900w × <600v"
  • Select all filtered files and run a metadata template from the Favorites menu to mark them as Rejected
  • Deactivate the first filter and run "Portrait/Square, <720v"
  • Repeat the select all/reject
  • Clear the filter
  • Begin sorting

It's not like that takes hours or anything, I just liked the idea of an automated category system that did it all dynamically.