Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

How do I MEASURE a height/width ratio?

Community Beginner ,
Oct 11, 2019 Oct 11, 2019

So you know that dumb program for losers called GIMP that doesn't even cost a million dollars? Well, it DOES have this one little nifty wherein if I measure a rectangle, it actually AUTOMATICALLY, without the error-prone process of setting tiny four-figure numbers into an off-app calculator, MEAURES THE ASPECT RATIO!

Check it out:

clipboard_image_0.pngexpand image

 

That doesn't happen in PS. But what I'm wondering is if there is ANY way to simply draw OR EVEN select a rectangle for the purposes of measureing a ratio automatically in this way. That's, right I said MEAsURING. Not to crop an image or layer to a specific aspect ratio, not to draw a fill of a predetermined size, or warp an image to a certain dimension, not to rasturbate an object expansion, simply to make a rectangle and KNOW WHAT IT IS AUTOMATICALLY. This would be extremely useful for my purposes. 

Internet is coming up blank.   Any suggestions?

1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 11, 2019 Oct 11, 2019

If you actually want to draw a shape to a know aspect ratio, then use the path options in the menu bar.

clipboard_image_0.pngexpand image

If you want to measure the aspect ratio, you can use this script that just reduces one of the ratio values to 1.

#target photoshop;
var doc = activeDocument;
var lBounds = doc.activeLayer.bounds
var hor = lBounds[2]-lBounds[0];
var vert = lBounds[3]-lBounds[1];
var max = Math.max(hor,vert)
var min = Math.min(hor,vert)

if(hor>vert){alert(max/min + ':' + min/min)}
else {alert(min/min +':' +max
...
Translate
Adobe
Community Expert ,
Oct 11, 2019 Oct 11, 2019

If you actually want to draw a shape to a know aspect ratio, then use the path options in the menu bar.

clipboard_image_0.pngexpand image

If you want to measure the aspect ratio, you can use this script that just reduces one of the ratio values to 1.

#target photoshop;
var doc = activeDocument;
var lBounds = doc.activeLayer.bounds
var hor = lBounds[2]-lBounds[0];
var vert = lBounds[3]-lBounds[1];
var max = Math.max(hor,vert)
var min = Math.min(hor,vert)

if(hor>vert){alert(max/min + ':' + min/min)}
else {alert(min/min +':' +max/min)};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2019 Oct 11, 2019

I don’t want to draw a shape (as stated), and more importantly I DON’T know the aspect ratio. I mean, yeah, in one particular instance I can figure it out with a calculator, but the point of my post was to avoid that whole thing, as I am often going to have to calculate varying, odd ratios (1.34:1, 2.7:1, 1.91:1 for instance) for different projects and I’d rather not have to run equations on my own when the computer is can do it faster and more accurately.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2019 Oct 11, 2019
Uhh no- actually. That script is perfect. Sorry! And thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 10, 2023 Nov 10, 2023
LATEST

This doesn't work for me. im using PS 2023

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 11, 2019 Oct 11, 2019

Did you read the second part of my post where the script will measure for you and display the results, so that all you have to do is copy them?

 

clipboard_image_0.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 11, 2019 Oct 11, 2019

From my previous explorations of aspect ratio, there are at least three different ways to express the ratio. Take the following 1920x1080 canvas:

 

Doc-Info-Script.pngexpand image

 

However, it is not always that easy, different input can create some "interesting" output:

 

Dimensions: 153 x 92 pixels

Aspect Ratio:

1.66:1 / 3.32:2 / 6.64:4 (Basic)

153:92 (GCD)

5:3 (Farey)

16:9 (Adobe Bridge)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2019 Oct 12, 2019

I checked your blog, Stephen and I see you had to pull the code for your Document Info script. Can you post it here?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2019 Oct 12, 2019

Sure, I’ll update this placeholder:

 

 

#target photoshop
//stackoverflow.com/questions/1186414/whats-the-algorithm-to-calculate-aspect-ratio-i-need-an-output-like-43-169
var savedRuler = app.preferences.rulerUnits;        
app.preferences.rulerUnits = Units.PIXELS;
function gcd(a, b) {
    return (b == 0) ? a : gcd(b, a % b);
}
var w = app.activeDocument.width.toString().replace(' px', '');
var h = app.activeDocument.height.toString().replace(' px', '');
var r = gcd(w, h);
var mp = w * h / 1000000
var pix = w * h
var ppiRes = app.activeDocument.resolution;
var ppcmRes = ppiRes/2.54
var ratio = w / h
var docName = app.activeDocument.name;
var wMetric = w / 72 * 2.54
var hMetric = h / 72 * 2.54
var wInches = w / 72
var hInches = h / 72
/////////////////////////////////////////////////////////////////////
    var doc = app.activeDocument    
    var w = doc.width.toString().replace(' px', '');
    var h = doc.height.toString().replace(' px', ''); 
        
    function aspect_ratio(val, lim) {

    var lower = [0, 1];
    var upper = [1, 0];

    while (true) {
        var mediant = [lower[0] + upper[0], lower[1] + upper[1]];

        if (val * mediant[1] > mediant[0]) {
            if (lim < mediant[1]) {
                return upper;
            }
            lower = mediant;
        } else if (val * mediant[1] == mediant[0]) {
            if (lim >= mediant[1]) {
                return mediant;
            }
            if (lower[1] < upper[1]) {
                return lower;
            }
            return upper;
        } else {
            if (lim < mediant[1]) {
                return lower;
            }
            upper = mediant;
        }
    }
}
/////////////////////////////////////////////////////////////////////
app.preferences.rulerUnits = savedRuler;
alert('Document Info' + '\n' + 'Document Name: ' + docName + '\n' + 'Dimensions: ' + w + ' x ' + h + ' pixels' + '\n' + 'Dimensions: '  + Math.round(wMetric * 100) / 100 + ' x ' + Math.round(hMetric * 100) / 100 + ' cm / ' + Math.round(wInches * 1000) / 1000 + ' x ' + Math.round(hInches * 1000) / 1000 + ' inches' + '\n' + 'Resolution: ' + Math.round(ppiRes * 10) / 10 + ' ppi / ' + Math.round(ppcmRes * 1000) / 1000 + ' ppcm' + '\n' + 'Megapixel Value: ' + Math.round(mp * 10) / 10 + ' MP' + ' (' + pix + ' pixels)' + '\n' + 'Aspect Ratio:' + '\n' + ratio.toFixed(2) + ':1' + ' / ' + ratio.toFixed(2) * 2 + ':2 / ' + ratio.toFixed(2) * 4 + ':4' + ' (Basic)' + '\n' + w / r + ':' + h / r + ' (GCD)' + '\n' + aspect_ratio(w / h, 50).toString().replace(',', ':') + ' (Farey)');

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines