Photoshop Script to create text in a bitmap image in Photoshop

拈花ヽ惹草 提交于 2019-12-21 23:47:48

问题


I have very large size 1-bit images that I need to write arrays of text to in Photoshop. I can do this in javascript by converting the images to grayscale and then creating a new layer for each block of text, but I would like to be able to write text directly onto the 1-bit bitmap to save time. Is there a way to do this in javascript?


回答1:


You can create text with scripting. You will need to be in grayscale (or RGB) to do so. Here's a basic text function. You will have to position the text after it is created as there is no way of getting it's size before it's creation. Hope this helps.

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
}


来源:https://stackoverflow.com/questions/19280465/photoshop-script-to-create-text-in-a-bitmap-image-in-photoshop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!