I am using the following script for drawing a set of paths onto a photoshop image.

    var docRef= app.activeDocument;
    app.displayDialogs = DialogModes.NO;

    var currentRulerUnits = app.preferences.rulerUnits;
    var currentTypeUnits = app.preferences.typeUnits;
    var currentDialogMode = app.preferences.displayDialogs;

    app.preferences.rulerUnits = Units.PIXELS;
    app.preferences.typeUnits = TypeUnits.PIXELS;

    var height= docRef.height;
    var width = docRef.width;

    var isHorizontal = false;
    var backgroundlayer = docRef.artLayers.getByName("Background");

    var layer1,layer2,layer3,layer4;
        // Copy and paste the layers in such a way that they are in a horizontal orientation.
        layer1 = backgroundlayer.duplicate();
        layer1.name = "A"

        layer2 = backgroundlayer.duplicate();
        layer2.name= "B"

        layer3 = backgroundlayer.duplicate();
        layer3.name = "C";

        layer4 = backgroundlayer.duplicate();
        layer4.name= "D";
        layer1 = backgroundlayer.duplicate();
        layer1.name = "A";

        layer2 = backgroundlayer.duplicate();
        layer2.name= "B";

        layer3 = backgroundlayer.duplicate();
        layer3.name = "C";

        layer4 = backgroundlayer.duplicate();
        layer4.name= "D";

    var topXspread = .18; // 25 % Percentage expressed as decimal
    var topYhighspread = 0.2; // 20 %
    var topYlowspread = 0.6; // 80%
    var yminspread = 0.05; // 5 %
    var smalltoffset = yminspread/2;
    var overallYoffset = 100; // units are in pixels
    var midpointYoffset = -75;

    var point1 = GeneratePathPointInfo(Math.floor((width/2) * (1 - topXspread)),overallYoffset+Math.floor(height/2 *(1 + yminspread)));
    var point2 = GeneratePathPointInfo(Math.floor((width/2)),overallYoffset+Math.floor(height*(topYhighspread)));
    var point3 = GeneratePathPointInfo(Math.floor((width/2)*(1 + topXspread)),overallYoffset+Math.floor(height/2 *(1 + yminspread)));
    var point4 = GeneratePathPointInfo(Math.floor((width/2)),overallYoffset+Math.floor(height* topYlowspread));
    var point5 = GeneratePathPointInfo(Math.floor((width/2)),midpointYoffset+overallYoffset+Math.floor(height/2));


    var point1small = GeneratePathPointInfo(Math.floor(width/2 * (1 - topXspread)),overallYoffset+Math.floor((height/2 *(1 + yminspread))+ (height *smalltoffset)));
    var point3small = GeneratePathPointInfo(Math.floor(width/2*(1 + topXspread)),overallYoffset+Math.floor((height/2 *(1 + yminspread))+ (height *smalltoffset)));
    var point4small = GeneratePathPointInfo(Math.floor(width/2),overallYoffset+Math.floor((height* topYlowspread)+ (height *smalltoffset)));
    var point6small = GeneratePathPointInfo(Math.floor(width/2),overallYoffset+Math.floor((height* topYlowspread)+ (height * 6 * smalltoffset)));

    function GenerateTrianglePathItem(point1,point2,point3,name,docRef){
        var spi = new SubPathInfo();
        spi.closed = true;
        spi.operation = ShapeOperation.SHAPEXOR;
        spi.entireSubPath = [point1,point2,point3];
        var line = docRef.pathItems.add(name, [spi]);

    function GenerateLinePathItem(point1,point2,name,docRef){
        var spi = new SubPathInfo();
        spi.closed = true;
        spi.operation = ShapeOperation.SHAPEXOR;
        spi.entireSubPath = [point1,point2];
        var line = docRef.pathItems.add(name, [spi]);

    function GeneratePathPointInfo(x,y){
        var startPoint = new PathPointInfo();
        startPoint.anchor = [x,y];
        startPoint.leftDirection = [x,y];
        startPoint.rightDirection = [x,y];
        startPoint.kind = PointKind.CORNERPOINT;
        return startPoint;

The co-ordinates for the points (Point1, 2, 3 ..) are being calculated correctly and are withing the bounds of the image. However, the final path drawn is being drawn completely outside the image bounds.

Can anyone help me with why this is happening so?

  • I am guessing it has something to do with different co-ordinates units used for images and paths. But I am not able to pin-point how to solve the problem. Commented Apr 25, 2016 at 16:50
  • Ok. When I set the PPI of the image to 72, everything works. Can anyone explain why this happens and how I can modify my script to ensure that it works with images of Any PPI Commented Apr 25, 2016 at 16:55
  • 1
    A quick guess.. your x/y coordinates are using points instead of pixels. at 72PPI 1px == 1pt so it would make sense. I'm more used to scripting in AI and havn't got time to test now but that's what I would look at.
    – Cai
    Commented Apr 25, 2016 at 17:58
  • Can you explain why 72 ppi implies 1 point is 1 pixel? Commented Apr 26, 2016 at 3:44
  • 1
    You can easily see this by setting up a PSD at 72ppi, and switching the rulers from pixels to points, the numbers will be the same. Change the resolution to 300ppi (or anything else) without changing the pixel size. Switch the rulers from pixels to points again and the points will be different.
    – Cai
    Commented Apr 26, 2016 at 6:04

1 Answer 1


I'm not used to scripting with Photoshop so I'm not sure if there is a way to get PathPointInfo to work in pixels—seems there should be—but I can't find it.

One solution is to just change the document resolution to 72PPI. You can save the initial resolution at the beginning of the script, change to 72PPI then change back to the initial resolution once you are finished. I just tested this and it works with no problem.

var docRef= app.activeDocument;
app.displayDialogs = DialogModes.NO;

// Starting resolution
var startResolution = docRef.resolution;

// Change resolution to 72ppi without changing pixel size
docRef.resizeImage(undefined, undefined, 72, ResampleMethod.NONE );


// Reset back to starting resolution
docRef.resizeImage(undefined, undefined, startResolution, ResampleMethod.NONE );
  • I have actually implemented this temporarily. However making the image from, say 300 ppi to 72 ppi, will it not affect the quality of the image? Even if we change the ppi back to original value. Commented Apr 26, 2016 at 6:55
  • 1
    No. as long as you don't change the pixel dimensions (ResampleMethod.NONE) there will be no affect at all.
    – Cai
    Commented Apr 26, 2016 at 6:56
  • Awesome. Can you point me to any resources on how image handling, ppi and other details work? Commented Apr 26, 2016 at 6:57
  • 1
    This post has some good info on resolution. Generally speaking PPI doesn't matter unless you are printing, all that matters on screen is pixel dimensions.
    – Cai
    Commented Apr 26, 2016 at 7:01
  • 1
    No problem. Glad to help :)
    – Cai
    Commented Apr 26, 2016 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.