如何在Photoshop中将一堆文件的每个文件名转换为文本图层(并保存)?
文件夹1:文件的混乱
文件夹2:几乎相同的文件,但每个文件的文件名都贴在其图像上
这是一个被黑屏攻击的片段。我似乎无法得到的错误是如何将activeDocument设置为当前打开的错误。 http://pastebin.com/b0fqG9v4
答案 0 :(得分:4)
还没有被标记为已回答所以这里是CS的一个javascript示例(并且应该也适用于更高版本),以防有人关心这样的事情。这将打开源文件夹中的每个图像文件并添加新的文本图层。将文件名设置为文本图层的内容,然后将新文件保存到输出位置。
它并没有真正尝试将文字放在图像上,这当然可能但很复杂。
如果您将颜色管理设置为在打开具有与工作颜色空间不匹配的嵌入配置文件的文件时发出警告,则会出现配置文件不匹配对话框。您可以设置首选项自动处理这种情况。
function main ()
{
if (0 < app.documents.length)
{
alert ("Please close all open documents before running this script.");
return;
}
// Use folder selection dialogs to get the location of the input files
// and where to save the new output files.
var sourceFolder = Folder.selectDialog ("Please choose the location of the source image files.", Folder.myDocuments);
var destFolder = Folder.selectDialog ("Please choose a location where the new image files will be saved.", sourceFolder);
var files = sourceFolder.getFiles();
for (var i = 0; i < files.length; i++)
{
var f = files[i];
if (f instanceof Folder)
continue;
// If there are no other documents open doc is the active document.
var doc = app.open (f);
var layer = doc.artLayers.add ();
layer.bounds = [0,0,doc.width,doc.height];
// Now make the layer into a text layer and set parameters.
// The text will be centered, in the hideous default font, and white.
// Note that font size depends not just on the point size, but also
// on the resolution, which is NOT being set anywhere.
layer.kind = LayerKind.TEXT;
layer.textItem.position = [Math.round (doc.width / 2),Math.round (doc.height / 2)];
layer.textItem.justification = Justification.CENTER;
layer.textItem.color.rgb.hexValue = "FFFFFF";
layer.textItem.size = 60;
// Get the file name and set it as the text this assumes the full path is not wanted.
// to set the full path swap fsname for name.
layer.textItem.contents = File.decode (f.name);
doc.flatten ();
// Save as a new JPG file with these options.
var options = new JPEGSaveOptions ();
options.quality = 8;
var outputFile = new File (destFolder.absoluteURI + "/" + f.name);
doc.saveAs (outputFile, options, false, Extension.LOWERCASE);
doc.close ();
}
}
答案 1 :(得分:3)
显然,Photoshop可以通过Javascript编写脚本,因此使用虚拟文件作为模型,您应该能够做到所需。以下是有关Photoshop脚本的一些资源: