<p>You need to take your width and height and make them into a fraction, then <a href="https://en.wikipedia.org/wiki/Irreducible_fraction" rel="nofollow noreferrer">reduce it</a>. To do that, you'll need to find the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor" rel="nofollow noreferrer">greatest common divisor</a> of the numerator and denominator, and divide them both by that. </p>

<p>Now take the new fraction you got by dividing both the numerator and denominator by the greatest common divisor and do it again. Repeat this process until the greatest common divisor is 1. At that point you have your irreducible fraction and you can print it.</p>

<p>Another way to do it is to use <a href="https://en.wikipedia.org/wiki/Euclidean_algorithm" rel="nofollow noreferrer">Euclid's Algorithm</a>.</p>

<p><strong>Example:</strong></p>

<p>Let's look at your top example, 1,000 x 1,200</p>

<pre><code>1,000 / 1,200 = ?
</code></pre>

<p>We can see by examination that they both end in "00" so they're both divisible by 100. So start there:</p>

<pre><code>1,000 ÷ 100 = 10
1,200 ÷ 100 = 12
</code></pre>

<p>Next, we see that 10 and 12 are both even, so they're both divisible by 2:</p>

<pre><code>10 ÷ 2 = 5
12 ÷ 2 = 6
</code></pre>

<p>Finally, we see that 5 and 6 share no common factors besides 1. (This is because 5 is prime, so its only factors are 5 and 1. 6 has the factor 2 and 3, as well as 1 and 6.) So we have reached the end. The reduced fraction is 5 / 6.</p>

<p><strong>One More Thing</strong></p>

<p>You might also want to be able to detect cases of irrational ratios, such as <a href="https://en.wikipedia.org/wiki/Golden_ratio" rel="nofollow noreferrer">the golden ratio</a>, which is quite popular in visual arts. Such a ratio will not be possible to divide into small integers, so checking whether <code>width / height</code> is within some small distance of the golden ratio may be sufficient.</p>

CC BY-SA 3.0
2017-03-12T23:12:01.090Z
Can you give an example with numbers? Would appreciate.
funguy
CC BY-SA 3.0
2017-03-14T11:31:56.570Z
What about other value 1000x1333 it does not add up. It seems like a few people are saying that aspect ratio of this is 3:4, but if I try to count it is always 1000x1333. How they get 3:4 for this?
funguy
CC BY-SA 3.0
2017-03-14T16:37:34.137Z
That's a case of integer rounding. Technically, 3:4 would be a ratio of 0.75, whereas 1000:1333 is 0.750187546886722... So it's very close to 3:4, but not exact. So another way you could approach this is to have a table of common aspect ratios (like 1:1, 2:1, 3:4, 4:5, 16:9, etc.) and then find the one that's closest. Or you could round the result of the width / height to some decimal amount and then compare.
user1118321
CC BY-SA 3.0
2017-03-12T22:33:13.340Z
2017-03-13T00:44:50.290Z
2017-03-13T00:44:50.290Z
user1118321
<p>One way you could do it is by writing the dimensions as a fraction, and simplifying that fraction (dividing each of the numbers by their greatest common denominator). From that you can then create a string and format it as [simplified numerator]:[simplified denominator].</p>

<p><a href="https://stackoverflow.com/questions/4652468/is-there-a-javascript-function-that-reduces-a-fraction">This SO question</a> talks about this too, and it shows some code to implementing it in JavaScript and also suggests some libraries... although I don't know what language you're using, I think this will still help.</p>

CC BY-SA 3.0
2017-03-12T09:04:58.073Z
2017-03-12T09:04:58.073Z
2017-05-23T12:39:19.850Z
Leon
<p>What formula is for counting aspect ratio of the image as in this site:</p>

<p><a href="https://www.ninjaunits.com/calculators/aspect-ratio/" rel="nofollow noreferrer">Aspect ratio calculator (ARC) | NinjaUnits</a></p>

<p>For example: </p>

<pre><code> 1000x1200 its aspect ratio 5:6 
 1000x1333 its aspect ratio 3:4
 2592x3888 its aspect ratio 2:3
</code></pre>

<p>I want to determine this by handling an uploaded image so it should be a formula for counting this, but did not figure out this yet.</p>

CC BY-SA 3.0
2017-03-12T19:03:31.093Z
Just to be clear, you want the integer ratio and not the actual value? For example, the aspect ratio is just `width` / `height`, so for 1000x1200, it's 1000/1200 = 0.8333... But if you want to print it out as a ratio with a format like 16:9, then it's slightly more complicated (though not much). But it's not clear from your question which one you're asking about.
user1118321
CC BY-SA 3.0
2017-03-12T21:06:23.100Z
Yes, it is 1000/1200 = 0.8333, but how you actually get 5:6 by knowing just  this - 1000/1200 = 0.8333 ?
funguy
<image-processing>
How to count aspect ratio of an image when you have dimensions?
funguy
# How to count aspect ratio of an image when you have dimensions?

(Asked by: username_0 on 2017-03-11)

What formula is for counting aspect ratio of the image as in this site:

[Aspect ratio calculator (ARC) | NinjaUnits](https://www.ninjaunits.com/calculators/aspect-ratio/)

For example:

```
 1000x1200 its aspect ratio 5:6 
 1000x1333 its aspect ratio 3:4
 2592x3888 its aspect ratio 2:3

```

I want to determine this by handling an uploaded image so it should be a formula for counting this, but did not figure out this yet.

**Tags:** image-processing

> **Comments:**
> **username_1**: Just to be clear, you want the integer ratio and not the actual value? For example, the aspect ratio is just `width` / `height`, so for 1000x1200, it's 1000/1200 = 0.8333... But if you want to print it out as a ratio with a format like 16:9, then it's slightly more complicated (though not much). But it's not clear from your question which one you're asking about.  
> **username_0**: Yes, it is 1000/1200 = 0.8333, but how you actually get 5:6 by knowing just  this - 1000/1200 = 0.8333 ?  

---

## 2 answers

### Answer by username_1 on 2017-03-12. Score: 2 | Accepted answer

You need to take your width and height and make them into a fraction, then [reduce it](https://en.wikipedia.org/wiki/Irreducible_fraction). To do that, you'll need to find the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of the numerator and denominator, and divide them both by that.

Now take the new fraction you got by dividing both the numerator and denominator by the greatest common divisor and do it again. Repeat this process until the greatest common divisor is 1. At that point you have your irreducible fraction and you can print it.

Another way to do it is to use [Euclid's Algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm).

**Example:**

Let's look at your top example, 1,000 x 1,200

```
1,000 / 1,200 = ?

```

We can see by examination that they both end in "00" so they're both divisible by 100. So start there:

```
1,000 ÷ 100 = 10
1,200 ÷ 100 = 12

```

Next, we see that 10 and 12 are both even, so they're both divisible by 2:

```
10 ÷ 2 = 5
12 ÷ 2 = 6

```

Finally, we see that 5 and 6 share no common factors besides 1. (This is because 5 is prime, so its only factors are 5 and 1. 6 has the factor 2 and 3, as well as 1 and 6.) So we have reached the end. The reduced fraction is 5 / 6.

**One More Thing**

You might also want to be able to detect cases of irrational ratios, such as [the golden ratio](https://en.wikipedia.org/wiki/Golden_ratio), which is quite popular in visual arts. Such a ratio will not be possible to divide into small integers, so checking whether `width / height` is within some small distance of the golden ratio may be sufficient.

> **Comments:**
> **username_0**: Can you give an example with numbers? Would appreciate.  
> **username_0**: What about other value 1000x1333 it does not add up. It seems like a few people are saying that aspect ratio of this is 3:4, but if I try to count it is always 1000x1333. How they get 3:4 for this?  
> **username_1**: That's a case of integer rounding. Technically, 3:4 would be a ratio of 0.75, whereas 1000:1333 is 0.750187546886722... So it's very close to 3:4, but not exact. So another way you could approach this is to have a table of common aspect ratios (like 1:1, 2:1, 3:4, 4:5, 16:9, etc.) and then find the one that's closest. Or you could round the result of the width / height to some decimal amount and then compare.  

---

### Answer by username_2 on 2017-03-12. Score: 1

One way you could do it is by writing the dimensions as a fraction, and simplifying that fraction (dividing each of the numbers by their greatest common denominator). From that you can then create a string and format it as [simplified numerator]:[simplified denominator].

[This SO question](https://stackoverflow.com/questions/4652468/is-there-a-javascript-function-that-reduces-a-fraction) talks about this too, and it shows some code to implementing it in JavaScript and also suggests some libraries... although I don't know what language you're using, I think this will still help.


---

