// Ratio column to show ratio as 2 integers seperated by a colon // image ratios are defined as 'width:height' of image // written as a colon separating two integers function OnInit(w) { w.name = 'Ratio'; w.version = '1.0'; w.desc = 'Column to show aspect ratio of image as 2 integers seperated by a colon'; w.url = ''; w.copyright = '(c)2023'; w.default_enable = true; w.min_version = '12.28'; } function OnAddColumns(z) { var y = z.AddColumn(); y.name = 'ratio'; y.label = 'Ratio'; y.justify = 'center'; y.type = 'wordsort'; y.autogroup = true; y.autorefresh = true; y.method = 'OnRatio'; } function gcd_iterative(x, y) { while(y) { var t = y; y = x % y; x = t; } return x; } function simplifyFraction(numerator, denominator) { // Get the greatest common factor of the numerator and denominator var gcd = gcd_iterative(numerator, denominator); // Divide the numerator and denominator by the GCD return { numerator: numerator / gcd, denominator: denominator / gcd, }; } function OnRatio(x) { var c = x.item; if (c.metadata != 'image') return; var width = c.metadata.image.picwidth; var height = c.metadata.image.picheight; var result = simplifyFraction(width, height); var antecedent = result.numerator; var consequent = result.denominator; x.value = antecedent + ":" + consequent; }