Calculate the ratio of your images or find new dimensions for resizing.
1. Find Aspect Ratio from Dimensions
2. Calculate Resized Dimensions
Enter current dimensions and one target dimension to find the other while maintaining the ratio.
What is Image Aspect Ratio?
The aspect ratio of an image is the proportional relationship between its width and its height. It is commonly expressed as two numbers separated by a colon, such as 16:9. For example, a 16:9 aspect ratio means that for every 16 units of width, there are 9 units of height.
Common Aspect Ratios
Ratio
Common Usage
Example Resolution
1:1
Instagram Posts / Profile Pictures
1080 x 1080 px
4:3
Old TVs / Computer Monitors
1024 x 768 px
3:2
DSLR Photography / Print
1500 x 1000 px
16:9
HD Video / YouTube / Modern TVs
1920 x 1080 px
21:9
Ultrawide Monitors / Cinematic Films
3440 x 1440 px
How to Calculate Aspect Ratio Manually
To calculate the aspect ratio manually, you need to find the Greatest Common Divisor (GCD) of the width and height. You then divide both the width and height by that GCD.
Example: For an image that is 1200px wide and 800px high:
The GCD of 1200 and 800 is 400.
1200 / 400 = 3
800 / 400 = 2
The Aspect Ratio is 3:2.
Why Aspect Ratio Matters
Understanding aspect ratio is critical for web designers and photographers to ensure that images don't appear stretched or squashed when displayed on different devices. It also ensures that your content meets the specific requirements of social media platforms, preventing unwanted cropping of important visual elements.
function getGCD(a, b) {
return b == 0 ? a : getGCD(b, a % b);
}
function calculateRatio() {
var w = Math.abs(parseInt(document.getElementById('origWidth').value));
var h = Math.abs(parseInt(document.getElementById('origHeight').value));
var resultDiv = document.getElementById('ratioResult');
if (isNaN(w) || isNaN(h) || w === 0 || h === 0) {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Please enter valid width and height values.';
return;
}
var common = getGCD(w, h);
var ratioW = w / common;
var ratioH = h / common;
var decimal = (w / h).toFixed(2);
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'The Aspect Ratio is ' + ratioW + ':' + ratioH + ' (' + decimal + ')';
}
function calculateResize() {
var origW = Math.abs(parseInt(document.getElementById('origWidth').value));
var origH = Math.abs(parseInt(document.getElementById('origHeight').value));
var targetW = Math.abs(parseInt(document.getElementById('targetWidth').value));
var targetH = Math.abs(parseInt(document.getElementById('targetHeight').value));
var resultDiv = document.getElementById('resizeResult');
if (isNaN(origW) || isNaN(origH) || origW === 0 || origH === 0) {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Please fill out the Original Width and Height in Section 1 first.';
return;
}
var ratio = origW / origH;
if (!isNaN(targetW) && targetW > 0) {
var newH = Math.round(targetW / ratio);
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'New Dimensions: ' + targetW + 'px x ' + newH + 'px';
document.getElementById('targetHeight').value = newH;
} else if (!isNaN(targetH) && targetH > 0) {
var newW = Math.round(targetH * ratio);
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'New Dimensions: ' + newW + 'px x ' + targetH + 'px';
document.getElementById('targetWidth').value = newW;
} else {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Please enter either a Target Width or a Target Height.';
}
}