Photoshop script: How to find distance of grapic center related to the upper left corner of canvas?

385 views Asked by At

My problem is this:

Is it possible to measure with Photoshop script (I use CS5.1) THE EXACT (x,y) of the center of the graphic (as shown in the image), related to the upper left corner of the canvas (0,0)? What is the tactic I should follow? Anyone has an idea? (The graphic is in its own layer, and I want to do the measure for each graphic, layer by layer, in order to form the layout in Corona).

2

There are 2 answers

0
Ghoul Fool On

To find the coordinates of the centre of the image you need to find the layer bounds, which will tell you the left, top, right and bottom values of the image. From this we can work out the width and height of the image and the centre (from the top left of the photoshop image)

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

// call the source document
var srcDoc = app.activeDocument;

// get current width values
var W = srcDoc.width.value;
var H = srcDoc.height.value;

var X = srcDoc.activeLayer.bounds[0]
var Y = srcDoc.activeLayer.bounds[1]
var X1 = srcDoc.activeLayer.bounds[2]
var Y1 = srcDoc.activeLayer.bounds[3]

var selW = parseFloat((X1-X));
var selH = parseFloat((Y1-Y));


var posX = Math.floor(parseFloat((X+X1)/2));
var posY = Math.floor(parseFloat((Y+Y1)/2));
alert(X + ", " + Y + ", " + X1 + ", " + Y1 + "\n" + "W: " + selW + ", H: " + selH + "\nPosition " + posX + "," + posY);
0
Rob Miracle On

Yes, in Photoshop, click on "Image" in the navigation menu, then choose Image Size. Take the width and divide by 2, take the height and divide by 2.