【问题标题】:Photoshop Automation of alignment of text layer with imagePhotoshop自动化文本层与图像对齐
【发布时间】:2013-10-01 16:57:07
【问题描述】:

我以前从未在 Photoshop 中编写过脚本,所以我想知道这是否可能。目前对超过 300 个文件手动完成以下操作。下一轮是 600 个文件,因此我正在研究自动化它。

步骤:

  1. 将图像大小设置为 54 像素高和 500 像素宽 -- 发现这是可行的。
  2. 图像左对齐。
  3. 创建文本图层并插入文本--发现可行。
  4. 将文本层与图像右侧对齐 1px。
  5. 修剪空白。

不胜感激任何帮助和指点。谢谢。

【问题讨论】:

    标签: photoshop


    【解决方案1】:

    此脚本将帮助您入门:请注意,在您的请求中,您没有提及原始图像将是什么,将其缩小到 500 x 54 会以一种或另一种方式拉伸它。第 2 步,左对齐图像,因为你没有提到你要对齐这个图像,所以省略了。我怀疑您正在处理一个大图像以及将其缩小的内容(只要它不小于 500 x 54)并从那里开始工作。我还省略了第 4 阶段,因为我将文本的位置硬编码为距右侧边缘 1 px(并且它以 Arial 字体大小 18 垂直居中)

    Anhyoo.. 您应该能够根据需要更改脚本。

    // set the source document
    srcDoc = app.activeDocument;
    
    //set preference units
    var originalRulerPref = app.preferences.rulerUnits;
    var originalTypePref = app.preferences.typeUnits;
    app.preferences.rulerUnits = Units.POINTS;
    app.preferences.typeUnits = TypeUnits.POINTS;
    
    // resize image (ignoring the original aspect ratio)
    var w = 500;
    var h = 54;
    var resizeRes = 72;
    var resizeMethod = ResampleMethod.BICUBIC;
    srcDoc.resizeImage(w, h, resizeRes, resizeMethod)
    
    //create the text
    var textStr = "Some text";
    createText("Arial-BoldMT", 18.0, 0,0,0, textStr, w-1, 34)
    srcDoc.activeLayer.textItem.justification = Justification.RIGHT
    
    //set preference units back to normal
    app.preferences.rulerUnits = originalRulerPref;
    app.preferences.typeUnits = originalTypePref;
    
    //trim image to transparent width
    app.activeDocument.trim(TrimType.TRANSPARENT, true, true, true, true);
    
    // function CREATE TEXT(typeface, size, R, G, B, text content, text X pos, text Y pos)
    // --------------------------------------------------------
    function createText(fface, size, colR, colG, colB, content, tX, tY)
    {
    
      // Add a new layer in the new document
      var artLayerRef = srcDoc.artLayers.add()
    
      // Specify that the layer is a text layer
      artLayerRef.kind = LayerKind.TEXT
    
      //This section defines the color of the hello world text
      textColor = new SolidColor();
      textColor.rgb.red = colR;
      textColor.rgb.green = colG;
      textColor.rgb.blue = colB;
    
      //Get a reference to the text item so that we can add the text and format it a bit
      textItemRef = artLayerRef.textItem
      textItemRef.font = fface;
      textItemRef.contents = content;
      textItemRef.color = textColor;
      textItemRef.size = size
      textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
    }
    

    【讨论】:

    • 伙伴,非常感谢。这绝对是一个很好的开始,我应该可以从这里开始。我会努力解决剩下的问题。
    【解决方案2】:

    您列出的所有内容都可以在脚本中执行。我建议您首先阅读 ExtendScript Toolkit 程序文件目录中的“Adobe Intro To Scripting”(例如 C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\SDK\English)

    【讨论】:

      猜你喜欢
      • 2012-06-17
      • 2014-10-06
      • 1970-01-01
      • 2011-01-14
      • 2016-06-19
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多