Javascript Photoshop:用于更改现有文本图层的文本颜色的语法
Javascript Photoshop: Syntax for changing text color of an already existing text layer
我创建了一个 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;
对文本添加进行编码可能更容易。这是我为这样的场合写的一个方便的功能。文本是对齐的居中,但您可以进行调整。(我会包含该部分功能,但它看起来像 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;
}
相关文章:
- 更改图层中单个矢量特征的图标
- 谷歌地图热图图层点半径
- 谷歌地图-更改图层图标大小
- 如何通过ID获取图层对象
- CS5隐藏图层的速度非常慢
- 开放图层导出为 KML 并保留我的地图样式
- 传单问题:使折线的图层组不可单击
- 将图层添加到另一个图层
- 图层删除(图像);在 Kinetic.js 中不起作用
- HTML5 Canvas 的初学者,使用图层
- 如何在“控制缩放”下的“打开图层”上添加一些图像
- 无法让 jQuery floatThead 处理嵌入在选项卡式图层中的表
- OpenLayers:自动将 EPSG 4326 - 文本图层的坐标转换为地图的投影 (EPSG:900913)
- 底图参考图层(文本)忽略选择更改时的不透明度
- Photoshop 脚本 - 如何在一种历史记录状态下创建文本图层
- 区分多个字体在同一文本图层
- 添加和转换图层的图像和文本,如Photoshop fx
- Photoshop 脚本:更改文本图层的文本
- Javascript Photoshop:用于更改现有文本图层的文本颜色的语法
- 创建一个切换按钮,在图层打开和图层关闭时改变文本