Javascript Photoshop: синтаксис для изменения цвета текста уже существующего текстового слоя

Я создал экшен фотошопа, который добавляет к фотографии строку белого текста. В этом действии я написал сценарий, который увеличивает размер холста и изменяет размер текста в пределах дополнительного пространства холста, чтобы он соответствовал размерам изображения, создавая «текстовую вкладку» на фотографии. Однако после реализации действия и сценария цвет текста во вкладке зачастую... не белый.

Какой синтаксис сценария я могу использовать, чтобы изменить цвет текстового слоя на белый, чтобы гарантировать, что он не изменит цвет случайным образом?

Для справки, вот часть моего скрипта, которая редактирует текстовый слой:

#target photoshop


var originalRulerUnits = app.preferences.rulerUnits;  
app.preferences.rulerUnits = Units.INCHES; 

var doc = app.activeDocument;  
var layer = doc.activeLayer;  

app.preferences.rulerUnits = Units.PIXELS; 

//create the color for the tab extension
var black = new SolidColor();  
black.rgb.hexValue = "111111";
app.backgroundColor = black;


//*****************************FOR EXTENDING CANVAS AND POSITIONING/RESIZING THE TEXT LAYER*********************************

var orgWidth = doc.width;
var orgHeight = doc.height;

if(orgWidth>orgHeight) //if document is landscape, resize text to fill a smaller portion of the tab
{
    layer.resize(((orgWidth-orgWidth*.2)/(layer.bounds[2]-layer.bounds[0]))*100,(orgWidth*.017/(layer.bounds[3]-layer.bounds[1]))*100,AnchorPosition.TOPLEFT);     

    doc.resizeCanvas(doc.width, (orgHeight + orgWidth*.04), AnchorPosition.TOPCENTER);

    layer.translate(undefined, new UnitValue(0-layer.bounds[1].as('px'),'px'));  
    layer.translate(undefined, orgHeight); 
    layer.translate(undefined, (orgWidth*.02-((layer.bounds[3]-layer.bounds[1])/2.3)));    


}
else //otherwise, resize text to fill a larger portion of the tab
{
    layer.resize(((orgWidth-orgWidth*.05)/(layer.bounds[2]-layer.bounds[0]))*100,(orgWidth*.017/(layer.bounds[3]-layer.bounds[1]))*100,AnchorPosition.TOPLEFT); 

    doc.resizeCanvas(doc.width, (orgHeight + orgWidth*.04), AnchorPosition.TOPCENTER);

    layer.translate(undefined, new UnitValue(0-layer.bounds[1].as('px'),'px'));  
    layer.translate(undefined, orgHeight); 
    layer.translate(undefined, (orgWidth*.02-((layer.bounds[3]-layer.bounds[1])/2.3))); 



}


var layerWidth = Number(layer.bounds[2] - layer.bounds[0]);
var dX = (orgWidth - layerWidth) / 2 - Number(layer.bounds[0]);
layer.translate(dX, undefined);


doc.flatten(); //flatten the text into the photo

app.preferences.rulerUnits = originalRulerUnits;  

person Dylan    schedule 11.06.2015    source источник


Ответы (1)


Возможно, вам будет проще закодировать добавление текста. Вот удобная функция, которую я написал для такого случая. Текст выравнивается по центру, но это можно настроить. (Я бы включил эту часть функции, но она выглядит как IF спагетти)

var x = (app.activeDocument.width.value)/2;
var y = (app.activeDocument.height.value)/2;

createText("Arial-BoldMT", 10.0, 255,255,255, "Gwen Stefanni is bananas", x, y)


// 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 = 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
  var just = Justification.CENTER;

  activeDocument.activeLayer.textItem.justification = just;
}
person Ghoul Fool    schedule 15.06.2015
comment
Спасибо, это было бы очень полезно для будущего использования! - person Dylan; 15.06.2015