Selecting image files based on Aspect Ratio
Posted: 19 Jul 2013 17:38
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.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.
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";
}
}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.