gpt4 book ai didi

Javascript Photoshop : Syntax for changing text color of an already existing text layer

转载 作者:太空宇宙 更新时间:2023-11-04 03:04:22 24 4
gpt4 key购买 nike

我创建了一个 photoshop Action ,可以将一串白色文本添加到照片中。在此操作中,我编写了一个脚本来扩展 Canvas 大小并调整额外 Canvas 空间内的文本大小以适合图像的尺寸,从而在照片上创建一个“文本选项卡”。但是,在执行 Action 和脚本之后,选项卡中的文本颜色往往……不是白色。

我可以使用什么脚本语法将文本层的颜色更改为白色,以确保它不会随机更改颜色?

作为引用,这里是我编辑文本层的脚本部分:

#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;

最佳答案

对文本添加进行编码可能更容易。这是我为这种场合编写的一个方便的函数。文本居中对齐,但您可以对其进行调整。 (我会包括那部分功能,但它看起来像意大利面条)

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;
}

关于Javascript Photoshop : Syntax for changing text color of an already existing text layer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30785513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com