This aspect ratio column makes no attempt to calculate fraction ratios from decimals.
I really think this is not a need for that. This column determines whether common aspect ratios match the keyword aspect ratio
to 2 decimals using a regular expression.
Different image sources often report decimal aspect ratios that differ very small from true fractions. If more decimals are needed, the code can be easily changed.
The aspect ratios that match are displayed as 4:3, 3:4,16:9, 9:16, 3:2, 2:3, 5:4, 4:5 or to 2 decimals. Other aspect ratios can be easily added to the code.
<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="no" autorefresh="yes" customgrouping="no" foldertype="all" header="Aspect" keyword="Aspect" maxstars="5" namerefresh="yes" reversesort="no" title="Aspect:Ratio" type="0">x=aspectratio;
ratio = RegEx(x, "(.*)(\..{2})", "\1\2");
output(x);
if ( ratio == RegEx(4 as double / 3 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "4:3";
}
elseif ( ratio == RegEx(3 as double / 4 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "3:4";
}
elseif ( ratio == RegEx(16 as double / 9 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "16:9";
}
elseif ( ratio == RegEx(9 as double / 16 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "9:16";
}
elseif ( ratio == RegEx(3 as double / 2 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "3:2";
}
elseif ( ratio == RegEx(2 as double / 3 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "2:3";
}
elseif ( ratio == RegEx(5 as double / 4 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "5:4";
}
elseif ( ratio == RegEx(4 as double / 5 as double , "(.*)(\..{2})", "\1\2") )
{
ratio = "4:5";
}
else
{
ratio = aspectratio_text;
}
return ratio;</evalcolumn>
2025-02-16 local time.
The regular expressions in this Evaluator Column need a small modification to align with Directory Opus 13.13.3. The Regular Expressions now need to match the entire string.
It is an easy fix. Use this instead.
<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="no" autorefresh="yes" customgrouping="no" foldertype="all" header="Aspect" keyword="Aspect" maxstars="5" namerefresh="yes" reversesort="no" title="Aspect:Ratio" type="0">x=aspectratio;
ratio = RegEx(x, "(.*)(\..{2}).*", "\1\2");
//output(x);
if ( ratio == RegEx(4 as double / 3 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "4:3";
}
elseif ( ratio == RegEx(3 as double / 4 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "3:4";
}
elseif ( ratio == RegEx(16 as double / 9 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "16:9";
}
elseif ( ratio == RegEx(9 as double / 16 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "9:16";
}
elseif ( ratio == RegEx(3 as double / 2 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "3:2";
}
elseif ( ratio == RegEx(2 as double / 3 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "2:3";
}
elseif ( ratio == RegEx(5 as double / 4 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "5:4";
}
elseif ( ratio == RegEx(4 as double / 5 as double , "(.*)(\..{2}).*", "\1\2") )
{
ratio = "4:5";
}
else
{
ratio = aspectratio_text;
}
return ratio;</evalcolumn>