I want to make a program that, for starters, list all image files in a folder and writes a warning if one dimension is (i.e.) double (2x) the other dimension, regardless of "image orientation".

I know how to do this, I divide the bigger dimension with the smaller dimension, and if the quotient is 2 or greater, there would be a warning...

Is there a best practise for this; should divide the bigger with the smaller dimension (and look for numbers higher than 1, i.e. 2) OR should I divide the smaller with the bigger dimension (and look for numbers lower than 1, i.e. 0.5)?

As a measure the program would then add padding to make image more square like. Actually I have done this already in Java code, now I try 'go'.

I hope this question could be useful.

  • 2
    $\begingroup$ A ratio is a ratio. It's already one value, even if you write it out with two integers. $\endgroup$ Jan 20, 2022 at 22:35
  • $\begingroup$ Ok, thanks, may I ask what the one value is for the ratio 4:3. $\endgroup$ Jan 21, 2022 at 23:05
  • $\begingroup$ A ratio is a fraction, a numerator divided by a denominator. The one value is computed by doing the division. $\endgroup$ Jan 21, 2022 at 23:22
  • $\begingroup$ Thanks, it's clear that ratio and quotient are the same thing, so I edited my question. But this TV aspect ratio 4:3 - is there a quotient? Maybe I can ask this elsewhere. $\endgroup$ Jan 21, 2022 at 23:40
  • $\begingroup$ I don't know what you mean by "quotient" other than the obvious: 4/3. $\endgroup$ Jan 22, 2022 at 0:31

2 Answers 2


Aspect ratio's are usually described in terms of width and height not bigger vs smaller. for example 16:9 is a width : height ratio. It doesn't matter if you pick width/height or height/width but being consistent is important. So pick one and stick with it. To check for a ratio where one dimension is over 2x the other dimension:

float ratio = width/height;
if( ratio >= 2.0  || ratio <= 0.5 ) { warn_ratio(); }

The same code works whether it is width/height or height/width.

Should they be saved as a single floating point value or two separate (usually integer) values? That doesn't matter. I suggest just programming it into obscurity with something like:

class Aspect {
     Aspect( int width, int height ) : ratio(width/height) {}
     float ratio;

Add a float conversion operator to the above class and it will automatically cast to a float (and a const float) as needed. If for some reason the code needs to store the ratio as two values later, it is easy to convert it and the cast operation to use two values instead.


There is no true standard for storing an aspect ratio as bytes. However, If you remember how ratio mostly written in math, it looks like this:




Thus, I would recommend you to transform your aspect ratio that way and only stores the right side as a float. If precision is more important than memory size, then make it double instead of float.

  • $\begingroup$ In my case - with images - there were only integers, width and height. $\endgroup$ Jan 23, 2022 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.