Selecting image files based on Aspect Ratio

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Selecting image files based on Aspect Ratio

Post by klownboy »

Hi,
Frequently, I find myself looking for image files that are a particular aspect ratio regardless of size (e.g., 16x9 (1920x1080) or 8x5 (1920x1200)) typically to collect jpgs for viewing or desktop wallpaper on different computers. To make it a bit easier, this little script will determine which files in a folder are a particular aspect ratio and highlight/select them for whatever operation I'm about to perform.

Code: Select all

  global $file, $selected;
   selfilter "*.jpg", f;                            // select jpg files
   if (get("View") < 4) {                           // view files in thumbnail view if not already
      #308; }
    $images_selected = get("selecteditemsnames", "|"); 
    #251;                                           // unselect all files
    foreach($file, $images_selected, "|") {         // edited to correct syntax
    sub "_FileChk"; }
    end(1==1);
  
"_FileChk";
   global $file, $selected;
   $p = property("#11", $file);                     // determine if the file is a picture
   
  if ($p == "Picture") {                            // checks properties to make sure it's a picture - really not necessary since we are filtering jpg files      
   $rotate = property("#245", $file);
    
   if (($rotate == "Rotate 90 degrees") || ($rotate == "Rotate 270 degrees")) {
    $orig_width = property("ImageY", $file);
    $orig_height = property("ImageX", $file); }
   else {
    $orig_width = property("ImageX", $file);
    $orig_height = property("ImageY", $file); }

    $orig_ratio = round($orig_width / $orig_height, 2);
  //Looking for files with a 16x9 aspect ratio in next line.  If you want to select files with a 8x5 aspect ratio use 1.6, 4x3 use 1.33, etc... 
   if (($orig_ratio == 1.77) OR ($orig_ratio == 1.78)) {
     $selected = $file;
     selectitems $selected, , ,"a";
     }
   }
It works fine, but it does do a bit of looping for each file to determine each image's aspect ratio. Regardless, it is quite fast at accomplishing the task. I was wondering if anyone had any ideas on how I might perform this task without all the looping. Could I somehow place each file in a report and then check each file in the report to see if it was the sought after aspect ratio or would that be just as cumbersome? Or maybe there's some other way that's not as laborious?

Thanks,
Ken

Edited the foreach line on 20 July 3013 to correct. Script wasn't selecting the last file that matched the criteria when it should.
Last edited by klownboy on 20 Jul 2013 14:26, edited 1 time in total.

highend
Posts: 14925
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Selecting image files based on Aspect Ratio

Post by highend »

Hi Ken,

{Dimensions} in a report works in Win7 as well.

Maybe you can just use:

Code: Select all

selfilter "*.jpg", f;
	text report("{Name}|{Dimensions}<crlf>", 1);
And do your computing with these informations.
But you'd need a foreach loop anyway.
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Selecting image files based on Aspect Ratio

Post by klownboy »

Hi highend,

Thanks and how have you been? I just came back from Ireland last week...visiting cousins, seeing sites and drinking Guinness.

I had noticed Don had increased the strength of "report" just a few days ago. I found out since that "ImageX" and "ImageY" don't work by themselves in report, but "prop:ImageX" and "prop:ImageY" work just fine when you want to get the dimensions individually. So the following works:

Code: Select all

text report("{name}|{prop:imageX}|{prop:imageY}<crlf>");
I say that because I'd probably have to do the math on the individual "X" and "Y" values as I did above to arrive at the aspect ratio since there are potentially limitless file sizes that could be at a given ratio though typically there are the standards like you would have in cameras or the sizes you see for desktop wallpaper (e.g., 1920x1200 or 1600x1200). In the end though I'm not sure if it's worthwhile using "report" if I still have to do the foreach loop, pulling each file name from report and do the math on each file which I suspect I would. :?:

Thanks,
Ken

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Selecting image files based on Aspect Ratio

Post by Filehero »

Hi Ken,

nice to hear that you must have been exceptionally fine recently going back to your roots. Ireland, one place still on my list of "must-have-been-there-before-you-die"-locations. One day I'll be there to enjoy this gorgeous island full of wilderness and mythic/rural landscapes, and to "hunt" huge pikes. Though I'm not so shure about Guinness yet. :mrgreen:

Leaving OT.

Code: Select all

text report("{name}|{prop:imageX}|{prop:imageY}<crlf>");
Your use case consists of two central tasks which can't be "outsourced" any further - at least with the current inbuild capabilities of Windows and XY.
1. Iterate over every single entry of a given list (here: all jpg's in a given folder).
2. Calculate a temporary property derived from two other properties provided by the host.

From 1. it's obvious you can't escape doing the loop on your own, which holds true for the aspect ratio as well (since this is the very reason why you decided to develop this script in the end. And I haven't myself found any hint that aspect ratio is already defined in one of those numerous meta information standards [1]). Within the SC context this just leaves the fetching of image X/Y dimensions as the only worthwhile entry point for further performance improvements.

Stripped down, it's about wether it's faster to get them a) as part of the starting list using XY's genuine SC report or by b) retrieving them on every file explicitly during looping (just as in the code of your opening post).

From the guts I assume a) to be quicker, but the question remains by which factor. I would do a "simple" test:
- create two script variants differing in the critical code (including the famous stoptime-startime=runtime debug statements)
- create a test folder containing 10^3 image files (either by copying 10 files and pasting them 100 times with automatic file increment on, or, in order to exclude any possible "mysterious" content-specific caching involved, by copying 10^3 unique image files using branch view)
- repeat n times: stop XY, start XY, run both scripts, note the runtimes

After several runs you should clearly see which approach is more efficient and get a feel on the perceived performance of the better one.

Hope this helps a bit.


Cheers,
Filehero


[1]: this makes me wonder since the aspect ratio is a first-class sibling of the image dimensions and therefore predestined to be saved alongside.

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Selecting image files based on Aspect Ratio

Post by klownboy »

Hi Filehero. I hope all is well. We had a great time in Ireland once again. We saw many very picturesque and photo worthy sites we hadn't seen on our last trip. Yes, I have a ton of photos. I'm regretting not having purchased a better camera before the trip. Oh well, before the next one. I'm now waiting for this new Canon 70D to be released this September at least to see in-depth reviews. They're calling it revolutionary. http://www.dpreview.com/previews/canon-eos-70d and http://www.youtube.com/watch?v=8H-X4vJXbkU

Thanks for taking the time to comment. The speed wan't really a big concern. It's was more a feeling that there would be a better and yes at the same time, more efficient way to accomplish the task. But, the reality is, it happens in the blink of an eye in a folder with over a hundred very high pixel count photos (4320x3240). When I get more time to kill I may write/test an alternate version.

I was experiencing a problem with the code (1st post) in that, when/if the very last photo in the folder was a "16x9" aspect ratio that I was looking for and should be selected, it wasn't being selected. I know it should have been selected since I renamed the photo placing it elsewhere in the folder and it was properly selected when the script was run. I discovered I had messed up the foreach syntax slightly...I corrected it above.

I may modify the code a bit to provide a drop down menu of common image aspect ratios (i.e., 3x2, 4x3, 16x9, 8x5) to be selected and place this on a CTB. Well, maybe a right click of an existing CTB.

Thanks again,
Ken

admin
Site Admin
Posts: 66097
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

OT: Canon

Post by admin »

Did you get your Canon? Is it good? I'm thinking of getting one, too... :biggrin:

Whoops, I'm thinking about the Canon EOS 700D, not the Canon EOS 70D...

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Selecting image files based on Aspect Ratio

Post by klownboy »

No, I still haven't bought a DSLR yet. I bought a Fugi X100s about a year ago. It's a fantastic camera but it's a fixed frame, no zoom. Great for street photography, people and travel but limited for landscape because it's fixed frame. I may wait a few more months. I'm currently looking at either the 70D or maybe springing for the brand new 7D Mark II, both more costly than the T5i (or 700D as they're called over there). Too many choices. Here's a link comparing the two.http://www.lightandmatter.org/2013/equi ... t-for-you/

admin
Site Admin
Posts: 66097
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Selecting image files based on Aspect Ratio

Post by admin »

Thanks -- yep: Too many choices. -- and thanks for the link.

PS: Hmm, that Fuji looks great... let me know if you sell yours... :)

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Selecting image files based on Aspect Ratio

Post by Filehero »

admin wrote:PS: Hmm, that Fuji looks great...
Fuji X-T1 looks even better and supports interchangeable lenses. It never stops .... :mrgreen:


Cheers,
Filehero
Last edited by Filehero on 09 Dec 2014 10:16, edited 1 time in total.

admin
Site Admin
Posts: 66097
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Selecting image files based on Aspect Ratio

Post by admin »

Well, I discovered the Fujifilm X100T just now! Man, I already love it... I'm almost beyond the point of no return. Looks like it has been made for me... :whistle:

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Selecting image files based on Aspect Ratio

Post by Filehero »

admin wrote:Well, I discovered the Fujifilm X100T just now! Man, I already love it... I'm almost beyond the point of no return. Looks like it has been made for me... :whistle:
Great option as well, the Fuji X-series clearly has one of the best inbuild JPEG-engines ever produced.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Selecting image files based on Aspect Ratio

Post by PeterH »

No zoom at all? Wouldn't be for me. About 5x would be OK - but nothing?

And the price...

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Selecting image files based on Aspect Ratio

Post by Filehero »

PeterH wrote:And the price...
Depends on your needs - the Fuji is fully worth the price asked for. Again, depends on your needs.

Primes vs. zooms: I do have a Pentax K-5, but use it with my prime lenses only, I even carry them up the mountains. The image quality simply is that better.


Cheers,
Filehero

admin
Site Admin
Posts: 66097
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Selecting image files based on Aspect Ratio

Post by admin »

I want quality pictures, and a solid simple beautiful tool. Price does not matter. ( ;) )

I have a camera with 5x zoom (Canon Powershot S110), but I rarely use the zoom (mostly to work against the default setting which tends to be too wide for my taste), and I find the general quality goes down a bit with zoomed pictures. I think the Fuji X100 has the perfect default for me.

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Selecting image files based on Aspect Ratio

Post by klownboy »

You can't get much better reviews for a camera, Fugi X100S or the latest model X100T) than these...
http://www.kenrockwell.com/fuji/x100t.htm
http://www.dpreview.com/reviews/fujifilm-x100s/ of course the X100T is now even better. Ken Rockwell's site had my X100S as the best all around camera for People, Family and Travel but now the title goes to the X100T. The people photo skin tones are amazing. The drawback is the fixed lense. It's like having a quality DLSR with only a prime lens. It certainly is solid and very nice quality. No regrets here.

Post Reply