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

Photoshop Script to create text in a bitmap image in Photoshop

本文关键字:Photoshop 文本 脚本 创建 图像 用于 位图      更新时间:2023-09-26

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

您可以使用脚本创建文本。您需要处于灰度(或 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
}