Skip to main content
Participant
May 26, 2019
Question

finding ratio of image and canvas for drawing

  • May 26, 2019
  • 5 replies
  • 2646 views

Hi,  a newbie  what i required from a program it to be able to upload an image then by entering the dimensions of the canvas the program would adjust the image pixels so the ratios matched  ,  instead of doing the manual maths -  so the canvas  and image could then be graphed depending on detail ,  but knowing and the proportions would be correct  -  I purchased photoshop months ago  under recommendations of the store and have found it unable to do do this and frustratingly hard to use for a occasional user   cheers

    This topic has been closed for replies.

    5 replies

    JJMack
    Community Expert
    Community Expert
    May 26, 2019

    An image file Canvas has an Aspect Ratio.  You can change this by adding additional empty canvas,  or Cropping off some canvas loose some image content, or distorting the images into the aspect ratio using some method like resampling the image unconstrained or using  content aware resize, or composting in some additional image content.

    Any image can be printed larger or smaller by changing the size of the pixel you print the image with. Changing the Print DPI does not change the images aspect ratio it will only change the print size. If you use very large pixels the you eyes will see each pixels and the images will not have sharp defined image detail. If you use very small pixels print size the image will have better find image detail  however you eye man not be able toe resolve down that far so you will net be able to read the small fine print. You need pixels for details and a pixel size that will print an acceptable size image for your intended use.  A billboard size print does not need to have a 300DPI print resolution a 3" x 2" wallet image need to have a high print resolution and a good amount of pixels

    JJMack
    Stephen Marsh
    Community Expert
    Community Expert
    May 26, 2019

    If it helps, I created a script to report various image info (most of it is available in the info panel, except ratio and megapixel). There are at least 3 different aspect ratio formulas, depending on the image proportions they may or may not match each other, so the more the merrier!

    #target photoshop

    // https://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)');

    Prepression: Photoshop – Document Info: Aspect Ratio Value Script

    Prepression: Downloading and Installing Adobe Scripts

    Michael Bullo
    Community Expert
    Community Expert
    May 26, 2019

    Another option which you could explore is the Crop tool. Within the options bar are numerous choices which, for example, allow you to set…

    • Ratio
    • Width, Height and Resolution
    • etc…

    Legend
    May 26, 2019

    This sounds easy to do in Image > Image size. I'm assuming your target canvas has a maximum width and height in inches. All you need to do is decide whether it will fill the width or the height. Turn OFF resample and turn ON constrain aspect ratio. Fill the target size in inches. Job done. No math at all.

    OR your canvas has a maximum size in pixels. Turn ON resample and choose target size in pixels. Still no math at all.

    If Image Size doesn't do what you want, I guess I don't understand your question.

    Trevor.Dennis
    Community Expert
    Community Expert
    May 26, 2019

    Perhaps if you tell us why you need to do this, we might be able to come at it from a different direction.

    What is your intended end result?

    Is this to do with photography, or some sort of digital art?

    A question like yours needs as much additional information as possible, if people are going to understand  what you want to achieve.