1

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

脚步:

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

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

4

2 回答 2

2

此脚本将帮助您入门:请注意,在您的请求中,您没有提及原始图像将是什么,并且将其缩小到 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
}
于 2013-10-01T08:57:07.333 回答
1

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

于 2013-09-26T18:09:31.827 回答