答案 0 :(得分:0)
你需要两件事。首先是一个将图层作为选区抓取的函数。其次,您需要获得图层边界 - 您可以从中计算出高度和宽度。
var currentLayer = app.activeDocument.activeLayer.name;
var currentLayerSelection = layer_selection();
var lb = get_selection_bounds();
alert(currentLayer + " layer bounds:\n" + lb[0] + ", " + lb[1] + ", " + lb[2] + ", " + lb[3]);
// function GET SELECTION BOUNDS ()
// ----------------------------------------------------------------
function get_selection_bounds()
{
try
{
var x = parseFloat(app.activeDocument.selection.bounds[0]);
var y = parseFloat(app.activeDocument.selection.bounds[1]);
var x1 = parseFloat(app.activeDocument.selection.bounds[2]);
var y1 = parseFloat(app.activeDocument.selection.bounds[3]);
var selW = parseFloat(x1-x);
var selH = parseFloat(y1-y);
// return the results as an array
return [x, y, x1, y1];
}
catch(e)
{
alert("Oops " + e)
}
}
function layer_selection()
{
var id1268 = charIDToTypeID( "setd" );
var desc307 = new ActionDescriptor();
var id1269 = charIDToTypeID( "null" );
var ref257 = new ActionReference();
var id1270 = charIDToTypeID( "Chnl" );
var id1271 = charIDToTypeID( "fsel" );
ref257.putProperty( id1270, id1271 );
desc307.putReference( id1269, ref257 );
var id1272 = charIDToTypeID( "T " );
var ref258 = new ActionReference();
var id1273 = charIDToTypeID( "Chnl" );
var id1274 = charIDToTypeID( "Chnl" );
var id1275 = charIDToTypeID( "Trsp" );
ref258.putEnumerated( id1273, id1274, id1275 );
desc307.putReference( id1272, ref258 );
executeAction( id1268, desc307, DialogModes.NO )
}
您可以计算出高度和宽度:
var layerWidth = lb[2] - lb[0];
var layerHeight = lb[3] - lb[1];
alert("Width, height: " + layerWidth + ", " + layerHeight);
至于角度..让我们说自己做要容易得多。
使用标尺工具 - 然后 Photoshop 将计算出角度。查看“图像”>“图像旋转”>“任意”,它会显示旋转画布以使其恢复水平的角度。