代码之家  ›  专栏  ›  技术社区  ›  SmIqbal

通过Photoshop Javascript获取图层的绘制区域尺寸

  •  1
  • SmIqbal  · 技术社区  · 6 年前

    如何通过Photoshop Javascript检查层的绘制尺寸(而不是画布或图像大小)?到目前为止,我一直试图在Photoshop Javascript手册/参考指南中找到此属性,但没有任何运气。下面是一幅仅供参考的图像,它为您提供了绘制区域的尺寸(高度和宽度),但不知何故,我想通过脚本获取此信息,以便在以后从图像中获取此信息时执行特定操作。谢谢

    Pixel Layer Properties

    2 回复  |  直到 6 年前
        1
  •  2
  •   InternetRebel    5 年前

    可以使用ArtLayer边界特性获取包含边界框坐标的数组,然后使用这些值生成由图层特性选项板显示的宽度和高度。例如,我有以下文档,“属性”选项板显示宽度和高度为4.17英寸。

    使用以下代码,我可以捕获坐标x1、y1、x2和y2,然后从x2中减去x1,从y2中减去y1,以获得与“特性”选项板的输出相匹配的宽度和高度:

    var activeDoc = app.activeDocument;
    var layerBounds = activeDoc.activeLayer.bounds;
    // this particular document, activeLayer.bounds returns:
    // 0.41666666666667 in, 0.41666666666667 in, 4.5833333333333 in, 4.5833333333333 in
    // x1, y1, x2, y2
    
    // we specify the vlaue property so we only get the number without the ruler unit
    var x1 = layerBounds[0].value;
    var x2 = layerBounds[2].value;
    var y1 = layerBounds[1].value;
    var y2 = layerBounds[3].value;
    
    // finally subtract x1 from x2 and y1 from y2 to get the widht and height and 
    // fix the size to 2 decimal units to match the Properties palette
    var layerPaintedWidth = (x2 - x1).toFixed(2); 
    var layerPaintedHeight = (y2 - y1).toFixed(2);
    
    // display the results in an alert dialog as 'W = 4.17, H = 4.17'
    alert("W = " + layerPaintedWidth + ", H = " + layerPaintedHeight);
    
        2
  •  1
  •   Perfikly Helfy    3 年前

    设置选择(例如:命令+选择图层),然后在跟踪选择标注的信息调色板中填充宽度和高度值。