Photoshop 脚本:更改文本图层的文本
Photoshop scripting: changing text of a text layer
因为我没有足够的时间来学习所有关于PS脚本的知识,我想知道,如果你可以帮助我。
这很简单。我想要一个JS脚本,它可以更改顶层的文本。例如:文本是"#005",脚本应该加 1,所以它说"#006"。之后,它应该导出(保存为网络和设备,透明度@ 1280x720)具有当前数字(006)的文件。
这是图层的屏幕(天哪,它是德语!!11):imageshack.us/photo/my-images/706/helpal.png
为反对者编辑:
请,为了帮助社区并避免误导/错误的信息(如果我在这种情况下做了任何信息),从而使 StackOverflow 成为一个更好的地方,请在下面添加一条评论,指出是什么让您认为代码或方向值得投反对票。如果有任何错误或误导,我会再学到一件事,我将不胜感激。
首先,您需要创建一个操作。
- 使用扩展名
- 保存以下代码
.jsx
。 - 打开您拥有的图像之一
- 创建一个新操作,如果面板尚未处于活动状态,请按面板下方的录制按钮
- 转到
File > Scripts > Browse
并选择该脚本 - 停止操作记录
- 转到创建文件的文件夹并删除该新文件
然后,您将需要自动化所有这些。没有打开的文档,
- 转到
File > Automate > Batch
- 从选项中选择必要的"设置"和"操作"名称
- 对于"源",保持"文件夹"处于选中状态,然后通过单击"选择..."按钮
- 这可能不是必需的(取决于您的颜色设置),但您可以选择第 3 和第 4 个选项:
Suppress File Open Options Dialogs
和Suppress Color Profile Warnings
。由于在录制时您没有包括打开文件的操作,因此未选择第一个选项Override Action Open Commands
。否则,它不会打开任何文件,但它仍然会尝试执行脚本 * 文件的数量。如有必要,Include All Subfolders
选择第二个选项。 - 单击"确定"按钮。
对于那些使用CS6的用户:Adobe Developer Connection,还有一点表明...
Adobe Photoshop CS6 不会安装 Scripting 文件夹。请使用以下链接手动安装示例、文档和脚本侦听器插件。
function getTextLayer(target) {
// this basically loops all the layers to find the
// upmost text layer with the content #nn... and returns it
if (target == null) return false;
var layers = target.layers,
layerLen = layers.length;
for (var i = 0; i < layerLen; i++) {
var layer = layers[i],
isLayerSet = layer.typename == 'LayerSet',
isValid = layer.kind == LayerKind.TEXT &&
/^'s*#'d+'s*$/.test(layer.textItem.contents);
// we're allowing spaces around the text just in case
if (!isLayerSet && !isValid) continue;
if (isLayerSet) {
var found = getTextLayer(layer);
if (found) return found;
} else return layer;
}
return false;
}
var doc;
try {
doc = app.activeDocument;
// the front document
} catch(e) {}
var txtLayer = getTextLayer(doc);
// obviously, the text layer if found
if (txtLayer) {
var num = txtLayer.textItem.contents.match(/'d+/)[0],
// find the numeric part
len = num.length,
// find the length of the numeric part
num = (parseInt(num,10)+1).toString();
// add 1 to that number
while (num.length < len) num = '0' + num;
// and adjust length if necessary so that e.g.
// 032 will not become 33 but it will become 033
txtLayer.textItem.contents = '#' + num;
// update layer content
var ext = '.png',
dir = decodeURI(doc.path) + '/png24',
// to use the same directory where the layered file exists
// just keep it as decodeURI(doc.path)
// I added a folder here, which actually does not exist
// but it doesn't matter because I'm making it create it
// below in case there's no such directory.
fileName = dir + '/' + num + ext,
i = 0;
if (!Folder(dir).exists) Folder(dir).create();
// create the directory if it doesn't exist
while (File(fileName).exists)
fileName = dir + '/' + num + '-' + (++i) + ext;
// if file with that name exists, add -n to the end of the name
var file = new File(fileName),
opts = new ExportOptionsSaveForWeb();
with (opts) {
format = SaveDocumentType.PNG;
PNG8 = false;
}
doc.exportDocument(file, ExportType.SAVEFORWEB, opts);
// save for web
}
if (doc) {
doc.close(SaveOptions.DONOTSAVECHANGES);
// close the original layered document without saving
}
doc = null;
// remove reference
相关文章:
- 更改图层中单个矢量特征的图标
- 谷歌地图热图图层点半径
- 谷歌地图-更改图层图标大小
- 如何通过ID获取图层对象
- CS5隐藏图层的速度非常慢
- 开放图层导出为 KML 并保留我的地图样式
- 传单问题:使折线的图层组不可单击
- 将图层添加到另一个图层
- 图层删除(图像);在 Kinetic.js 中不起作用
- HTML5 Canvas 的初学者,使用图层
- 如何在“控制缩放”下的“打开图层”上添加一些图像
- 无法让 jQuery floatThead 处理嵌入在选项卡式图层中的表
- OpenLayers:自动将 EPSG 4326 - 文本图层的坐标转换为地图的投影 (EPSG:900913)
- 底图参考图层(文本)忽略选择更改时的不透明度
- Photoshop 脚本 - 如何在一种历史记录状态下创建文本图层
- 区分多个字体在同一文本图层
- 添加和转换图层的图像和文本,如Photoshop fx
- Photoshop 脚本:更改文本图层的文本
- Javascript Photoshop:用于更改现有文本图层的文本颜色的语法
- 创建一个切换按钮,在图层打开和图层关闭时改变文本