Photoshop自动化文本图层与图像的对齐方式

时间:2013-09-26 11:06:59

标签: photoshop

我以前从未在photoshop中编写脚本,所以我想知道这是否可行。目前,手动完成以下300多个文件。下一轮是600个文件,因此我正在考虑自动化它。

步骤:

  1. 使图像尺寸达到54像素高度和500像素宽度 - 发现这是可行的。
  2. 左图对齐。
  3. 创建文本图层并插入文本 - 发现这是可行的。
  4. 将文本图层1px对齐图像右侧。
  5. 修剪空白区域。
  6. 感谢任何帮助和指示。感谢。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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
}
相关问题