Photoshop脚本在Photoshop中创建位图图像中的文本

时间:2013-10-09 19:05:13

标签: javascript photoshop photoshop-script photoshop-cs3

我有非常大的1位图像,我需要在Photoshop中编写文本数组。我可以通过将图像转换为灰度,然后为每个文本块创建一个新图层,在javascript中执行此操作,但我希望能够将文本直接写入1位位图以节省时间。有没有办法在javascript中执行此操作?

1 个答案:

答案 0 :(得分:3)

您可以使用脚本创建文本。您需要使用灰度(或RGB)才能执行此操作。 这是一个基本的文本功能。您必须在创建文本后对其进行定位,因为在创建之前无法获得文本的大小。希望这会有所帮助。

createText("Arial-BoldMT", 48, 0,128,0, "Hello World", 100, 50)
activeDocument.activeLayer.name = "Text";
activeDocument.activeLayer.textItem.justification = Justification.CENTER

function createText(fface, size, colR, colG, colB, content, tX, tY)
{
  // Add a new layer in the new document
  var artLayerRef = app.activeDocument.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
}
相关问题