Show (nearest) Aspect Ratio

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

Don, while we are on this topic, are all the "XYplorer-specific Special Properties" (e.g., #AspectRatio, #AspectRatio) listed in the help file locale / OS independent? I would assume that the properties that yield strictly numerical returns probably are. If that's the case you might want to note that in the help remarks. I think "ImageX" and "ImageY" are as well, but then again, they are not mentioned in that list.

Also, you state that these XY specific props are case insensitive. You might want to also state in the Windows system canonical properties section that they are case sensitive because they definitely are. Thanks.

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

Hey, in some spare time, I wrote a small script which will give you aspect ratio of an image. Right no big deal, but in addition as requested (by Stef123) in title of this thread, it will tell you if the image is not a standard or common ratio (e.g., 8:5, 16:5 or 5:7) and whether the picture is rotated. If it isn't a common aspect ratio, it will inform the user what the nearest common aspect ratio is. It determines using whether the picture is rotated using Windows canonical properties like "System.Photo.Orientation". Hopefully making it independent of OS version or language. So it should also get the image aspect ratio correct under most situations; XY's aspect ratio is sometimes reversed. Please read the notes up front for use. It will work for multiple (image) file selections. You can also modify a couple lines - see the notes - to add additional "common" ratios as well.
AspectRatio_capture.PNG
Please let me know if it doesn't work properly especially for other languages. I determine if it's an image file "picture" by using a Windows canonical property as well, "System.Kind". The only property I did not use Windows canonical properties was property("#AspectRatio") since I figure that result should be the same across languages.

Code: Select all

  // Select an image file or files. Run the script from a CTB ,catalogue or user command. A text box will appear informing the user of the image's aspect ratio,
  // and if it's a "common" aspect ratio or if it's not, inform you of the nearest aspect ratio.  It will also inform you if the picture is rotated or not.
  // In some cases, XY will not get aspect ration correct based on rotation (i.e., it might be backwards).  This should not. Also you can modify lines #23 & #30 and add additional "common" image ratios
  // klownboy, dated Feb 20, 2015

  End GetInfo("CountSelected") < 1, "At least one image file must be selected.", 0 ;
  foreach($file, <get selecteditemspathnames |>) {
    $fn=getpathcomponent($file, "file");
    if(property('System.Kind', $file) UnLikeI "picture") {
	   msg "The file, ". $fn ." is not an image!"; continue; }
    $rotate = property("System.Photo.Orientation", $file);
	 if (($rotate == 6) || ($rotate == 8)) {
           $orig_width = property("System.Image.HorizontalSize", $file);
	        $orig_height = property("System.Image.VerticalSize", $file);	
          $r = "rotated 90 or 270 degrees";
          $ratio = gettoken(property("#AspectRatio",$file), 2, ":","t") . : .  gettoken(property("#AspectRatio", $file), 1, ":","t");
     } else {
           $orig_width = property("System.Image.HorizontalSize", $file);
	        $orig_height = property("System.Image.VerticalSize", $file);	
		  $r = "not rotated";
          $ratio = property("#AspectRatio", $file);
     }
	 if ("|3:2|2:3|4:3|3:4|8:5|5:8|16:9|9:16|7:5|5:7|5:4|4:5|" UnLikeI *|$ratio|*) {$ratio = "not common";   //you can add additional "common" ARs here
	        if (($rotate == 6) || ($rotate == 8)) {
	           $pic_ratio =  gettoken(property("#AspectRatio", $file), 2, ":","t") / gettoken(property("#AspectRatio", $file), 1, ":","t");}
			else {
	           $pic_ratio =  gettoken(property("#AspectRatio", $file), 1, ":","t") / gettoken(property("#AspectRatio", $file), 2, ":","t");}

		 $smallest_ratio_dif = "begin";
	     foreach($ratio_item, "3:2|2:3|4:3|3:4|8:5|5:8|16:9|9:16|7:5|5:7|5:4|4:5", "|") {               //you can add additional "common" ARs here
	        if($ratio_item == "") {continue; }
			if (($rotate == 6) || ($rotate == 8)) {
	          $common_ratio =  gettoken($ratio_item, 2, ":","t") / gettoken($ratio_item, 1, ":","t"); }
			else {
	          $common_ratio =  gettoken($ratio_item, 1, ":","t") / gettoken($ratio_item, 2, ":","t"); }

		    $ratio_dif = round(abs($pic_ratio - $common_ratio), 2);

			if ($smallest_ratio_dif == "begin") {
			    $smallest_ratio_dif = $ratio_dif; $nearest_AR = "[" . $ratio_item . "]" . " is the nearest common Aspect Ratio"; }
            elseif ($ratio_dif < $smallest_ratio_dif) {
			    $smallest_ratio_dif = $ratio_dif;
                $nearest_AR = "[ " . $ratio_item . " ]" . " is the nearest common Aspect Ratio"; }
		 }
     }
   if($ratio == "not common") {
     $ratio = $ratio . "<crlf 2>" . $nearest_AR; }
   msg "". $fn .":<br><br>Dimensions:  ". $orig_width ." x ". $orig_height ."<br><br>Aspect Ratio:  " . $ratio ."<br><br>". $r .".";	  
  }
AspectRatio.zip
Stef123, I hope it works as requested. :) Its actually not a bad idea when someone is working a great deal with photos of various sizes as you do.
Ken
To see the attached files, you need to log into the forum.
Last edited by klownboy on 20 Feb 2015 16:39, edited 1 time in total.

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: Show (nearest) Aspect Ratio

Post by kunkel321 »

Could this be set up with Instant Color Filters? (just curious)
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

Hi kunkel321, someone please correct me if I'm wrong, but I don't believe you can call out a script in an instant color file though you could definitely have a PFA set to run based on file extension(s) and call out the script.
Ken

Stef123

Re: Show (nearest) Aspect Ratio

Post by Stef123 »

Thanks a ton Ken,
this works better than expected. :appl: :appl: I especially like the rotated info. And that it allows me to enter my own ratios, I've seen people print their photos on legal-size paper and the weirdest European formats, so this might come in handy one day.

Have not tried it on non-English systems yet. But since I am exposed to a wide gamut of locales, that's bound to happen over the next weeks.

Many thanks for taking the time to working this out in such detail. I really appreciate it. :tup: :D

About kunkel123's request - instead of flagging them visually, it may work to sort by custom columns. They can be of the type "Script" and by using a spin-off of Ken's script .... just a wild guess out of the blue, don't know if this is feasible at all.

ed: just on a sidenote, I added 1:1 and took a "square" screenshot, it turned out 1968x1836 - and sure enough, the script tells me it's closer to 1:1 than to 5:4 which it was before I added 1:1 to the recognized rations. GREAT. Works like a charm, reliable. :tup: :beer:

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Show (nearest) Aspect Ratio

Post by TheQwerty »

klownboy wrote:Hi kunkel321, someone please correct me if I'm wrong, but I don't believe you can call out a script in an instant color file though you could definitely have a PFA set to run based on file extension(s) and call out the script.
Ken
That's correct but you could expand this script to apply instant color filters highlighting the different aspect ratios.

Take a look at this post: http://www.xyplorer.com/xyfc/viewtopic. ... 55#p116555
I haven't gotten around to breaking this up like I mentioned but it should be fairly easy for you to modify it to work.

The challenge might instead be how you want to use color filters to convey information. :?
A different color for each aspect ratio is likely a bit of a headache in need of a good legend. ;)
Better might be to highlight all images with aspect ratio similar to the current/focused item or something like that.

Putting it in a custom column as Stef123 suggests or an extra tag column is likely the cleanest answer.

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

Thanks Stef123, I was thinking of the 1:1 aspect ratio last night but forgot to add it to the list this morning. I'm glad it will be of some use. I'll probably incorporate it into the one menu item I have for aspect ratio in my Photo Cropper script. That script really fell by the wayside, but I'll revisit it again and update to use more of the Windows canonical properties in attempt to make it more OS and language independent. You mentioned using photo cropping software. I know there's a bunch out there. What do you typically use? Even Irfanview has very much improved there cropping capabilities to include the more common cropping ratios.

TheQwerty, that would be a nice idea to have a script color coding of the image files according to aspect ratio. Maybe even nicer would be to also have a custom columns where the image files would be laid out/grouped by all the aspect ratios in order, like first all the 16:9, then all the 8:5, 3;2, 4;3, then 1;1 and what remains would be the "un-common" aspect ratios images. Those uncommon AR images could have a trigger to bring up something similar to the above dialog. It sounds like it may be possible in custom columns. What do you think? As you said, it's a bit of a nightmare looking at color coding when the colors for the various aspect ratios are scattered over a large folder of images.

Stef123

Re: Show (nearest) Aspect Ratio

Post by Stef123 »

klownboy wrote:You mentioned using photo cropping software. I know there's a bunch out there. What do you typically use?
That depends very much on the requirements. At home I have Photoshop droplets to batch-process automatically because I generally know my stuff. On the road when dealing with unfamiliar photos, I prefer to set the cropping frame manually, not automated. Jcropper is very leightweight - I run it from XY's CTB for the current file.
http://www.vieas.com/en/soft.html

Also portable: FastStone, press X for the crop board. Just like JCroppper you can set your own ratio-presets, the amound of darkening for the outsisde regions.

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

I use jcropper as well though not all the time. One issue that bothers me about that program is, why don't they immediately have the cropping lines appear when you open it with an image. It's a cropping only type program. Why should you have to hit a cropping button first before you begin to lay out the crop area with the mouse...it seems a little silly, but very click counts when you have much to do. I even sent them an email concerning that.

I've been using good old Irfanview much more. When you open it with an image you can immediately layout the crop lines with the mouse, hit ctrl-y, ctrl-s and you're done and it now has the fixed common aspect ratios automatic crop as well. It will layout the fixed crop and you can then easily move it around with the right mouse button...very slick. I wrote the Photo Crop script only because it works nicely with the thumbnail view in XY without having to open an external program though it does use Irfanview or Image Magick, it's behind the scenes (that old script I uploaded has been improved).
Thanks,
Ken

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Show (nearest) Aspect Ratio

Post by TheQwerty »

klownboy wrote:Those uncommon AR images could have a trigger to bring up something similar to the above dialog. It sounds like it may be possible in custom columns. What do you think? As you said, it's a bit of a nightmare looking at color coding when the colors for the various aspect ratios are scattered over a large folder of images.
I don't do much photo work so I'm not very opinionated on this... ;)

You could certainly use a custom column (assuming your script is quick enough to tolerate there*). I think I'd have it show the actual/closest aspect ratio for all images, but for those that are unknown/uncommon and thus showing the nearest include the actual ratio (or anything at all!) in parens or brackets after. This would keep the sorting in a logical order.

If you'd prefer to have the unknown/uncommon ratios all lumped together at the start/end and not with their nearest common ratio neighbors you could prepend the nearest ratio with an '~' for these items. I don't actually recommend this though, as I imaging having the unknown/uncommons grouped together within the common ratio groups is enough and the logical order is more useful overall.


The problem is, I imagine if you're working with photos you are most likely using a thumbnail or tile view where custom columns are less useful - and color filters are really the only option. At which point I'd suggest you use the same color for aspect ratios which are just rotated 90-degrees (16:9 and 9:16) to limit the total number of colors - since the user should be able to spot the difference in the thumb. It might also make sense to create a color-coded legend in the catalog that could then be visible while browsing - these could actually be scripts to filter/select by aspect ratio so that they act as more than just a legend.


It really all comes down to why you're caring about the aspect ratio of the image and how that matters to you while in XY. Which is not something I can answer. :P


EDIT: *If determining the (nearest) aspect ratio is too slow for a custom column then have the script write it to an extra tag and you'll keep all the benefits, lose the automation and "pollute" <xytagdat> a bit, but gain some better searching support.

Stef123

Re: Show (nearest) Aspect Ratio

Post by Stef123 »

TheQwerty wrote: working with photos you are most likely using a thumbnail or tile view where custom columns are less useful
Yes, but you could still sort and filter (?) by custom columns. Details with Thumbnails also nails it quite well.
TheQwerty wrote: ...have the script write it to an extra tag and you'll keep all the benefits
Very tempting, if only it would not pollute my tag-db with all those portable references I only need once.

@Ken
You're right, it makes no sense for JCropper to not kick off straight away. I didnt know Irfan allows preset ratios. 4.38 doesn't seem to have it, couldn't find a newer portable version. 4.38 also lacks the darker out-regions that give a better idea what the after-crop will look like.

The compare-feature (up to 4 pics) is my main reason for using FastStone. Wish it had Irfan's command line options, though. And larger icons, FS is unusable on hi-res unless you memorize the shortcuts. Always something …*sigh* which makes them miss the mark of the ONE perfect tool that would spare me lugging around so many different ones.
klownboy wrote:that old script I uploaded has been improved
PhotoCrop using Irfan? Still the same link as above?

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

TheQwerty wrote: I imagine if you're working with photos you are most likely using a thumbnail or tile view where custom columns are less useful
You are absolutely correct. I only use a custom columns which include photo size, aspect ratio etc. on a couple of miscellaneous and download folders. The bulk of my personal photos and even the wallpapers are all thumbnail views. The rotation factor is always a pain since there are many photos, which as far as camera information is concerned, are not rotated yet they're in a portrait view. (i.e., they may have a rotation of "normal" yet be a 3:4 or 2:3). I have a CC that I don't currently use that someone on the forum came up with that grouped files by extension (Grp Ext). That's what made me think of the grouping by the aspect ratios. The script above is relatively fast but once you apply it to hundreds of photos...who knows. I 'll have to give it some more thought, but I'm not sure this is worth pursuing much further.

Stef123, yes Irfanview has the presets for aspect ratio. Take a look under Edit | Create maximized selection (ratio). After selection, it will place the selection lines (e.g., 16x9) in the middle of the picture. Remember though you can move it around with the right mouse button. The free form crop is even easier in Irfanview, make the selection, hit ctrl-y and then ctrl-s which is also what you'd do after a preset selection.

Sorry to be confusing again, the photo cropper script posted is still the 2 1/2 year "old" version. One of these days after some additional testing, I'll post a newer version. Yes the even the old one used Irfanview (command line options behind the scenes) to accomplish the cropping. As I mentioned earlier the new one will use Irfanview or Image Magick. I know I've only DLed version 4.38 of Irfanview and it's the latest. Yet when I look in the Help | About box it says 4.39. Weird, it may be a typo.

Stef123

Re: Show (nearest) Aspect Ratio

Post by Stef123 »

klownboy wrote:Stef123, yes Irfanview has the presets for aspect ratio. Take a look under Edit
Ha, you're right. Thanks. I missed it because I used to press Ctrl Shift J for the lossless crop.
It still doesn't fade the unwanted part, though. Seems I am just not able to ignore the perimeter, no matter how hard I pretend not being influenced by it. Guess I am spoiled by other apps where I crank up the darkness to almost pitch-black. :titter:

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

Re: Show (nearest) Aspect Ratio

Post by admin »

klownboy wrote:Don, while we are on this topic, are all the "XYplorer-specific Special Properties" (e.g., #AspectRatio, #AspectRatio) listed in the help file locale / OS independent? I would assume that the properties that yield strictly numerical returns probably are. If that's the case you might want to note that in the help remarks. I think "ImageX" and "ImageY" are as well, but then again, they are not mentioned in that list.

Also, you state that these XY specific props are case insensitive. You might want to also state in the Windows system canonical properties section that they are case sensitive because they definitely are. Thanks.
1) Yes, locale / OS independent.
2) Thanks, made a note in the help.

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

Re: Show (nearest) Aspect Ratio

Post by klownboy »

Thanks Don on the answer concerning XYplorer-specific special properties being OS local specific. A specific question though for one in particular, "property("#AspectRatio", $file);", will the return on this vary from OS or locale? It wouldn't seem that it would since it's only 2 numbers with a colon in between. In other words to make it internationally bullet proof, do I have to use the Windows canonical properties for this specific case? Thanks.
Ken

Post Reply