<p>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 <em>is</em> important. So pick one and stick with it. To check for a ratio where one dimension is over 2x the other dimension:</p>
<pre><code>float ratio = width/height;
if( ratio &gt;= 2.0  || ratio &lt;= 0.5 ) { warn_ratio(); }
</code></pre>
<p>The same code works whether it is width/height or height/width.</p>
<p>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:</p>
<pre><code>class Aspect {
     Aspect( int width, int height ) : ratio(width/height) {}
     float ratio;
};
</code></pre>
<p>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.</p>

CC BY-SA 4.0
2022-01-22T17:43:30.733Z
2022-01-22T17:43:30.733Z
pmw1234
<p>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:</p>
<blockquote>
<p>1:20</p>
</blockquote>
<blockquote>
<p>1:0.33333</p>
</blockquote>
<blockquote>
<p>1:2.4</p>
</blockquote>
<p>Thus, I would recommend you to transform your aspect ratio that way and <strong>only stores the right side as a float</strong>. If precision is more important than memory size, then make it double instead of float.</p>

CC BY-SA 4.0
2022-01-23T16:17:02.607Z
In my case - with images - there were only integers, width and height.
Valter Ekholm
CC BY-SA 4.0
2022-01-22T05:57:05.673Z
2022-01-22T05:57:05.673Z
Thor-x86_128
<p>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 &quot;image orientation&quot;.</p>
<p>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...</p>
<p>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)?</p>
<p>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'.</p>
<p>I hope this question could be useful.</p>

CC BY-SA 4.0
2022-01-20T22:35:51.520Z
A ratio is a ratio. It's already one value, even if you write it out with two integers.
Nicol Bolas
CC BY-SA 4.0
2022-01-21T23:05:02.160Z
Ok, thanks, may I ask what the one value is for the ratio 4:3.
Valter Ekholm
CC BY-SA 4.0
2022-01-21T23:22:54.170Z
A ratio is a fraction, a numerator divided by a denominator. The one value is computed by doing the division.
Nicol Bolas
CC BY-SA 4.0
2022-01-21T23:40:42.807Z
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.
Valter Ekholm
CC BY-SA 4.0
2022-01-22T00:31:40.980Z
I don't know what you mean by "quotient" other than the obvious: 4/3.
Nicol Bolas
CC BY-SA 4.0
2022-01-22T00:45:02.597Z
4:3 is the same thing as four divided by three, or approximately 1.333.
Nathan Reed
CC BY-SA 4.0
2022-01-23T16:18:43.897Z
Aha, so it would be "how big is the width compared to the hight"
Valter Ekholm
<transformations><image>
Can an aspect ratio be shortened to one value, best practise
Valter Ekholm
# Can an aspect ratio be shortened to one value, best practise

(Asked by: username_0 on 2022-01-20)

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.

**Tags:** transformations, image

> **Comments:**
> **username_1**: A ratio is a ratio. It's already one value, even if you write it out with two integers.  
> **username_0**: Ok, thanks, may I ask what the one value is for the ratio 4:3.  
> **username_1**: A ratio is a fraction, a numerator divided by a denominator. The one value is computed by doing the division.  
> **username_0**: 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.  
> **username_1**: I don't know what you mean by "quotient" other than the obvious: 4/3.  
> **username_2**: 4:3 is the same thing as four divided by three, or approximately 1.333.  
> **username_0**: Aha, so it would be "how big is the width compared to the hight"  

---

## 2 answers

### Answer by username_3 on 2022-01-22. Score: 1 | Accepted answer

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.


---

### Answer by username_4 on 2022-01-22. Score: -1

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:

> 1:20

> 1:0.33333

> 1:2.4

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.

> **Comments:**
> **username_0**: In my case - with images - there were only integers, width and height.  

---

