0

如何在 Photoshop 中将一堆文件的每个文件名转换为文本层(并保存)?

文件夹 1:数百个文件

文件夹 2:几乎相同的文件,但每个文件名都贴在图像上

这是一个被黑掉的片段。我似乎无法解决的错误是如何将 activeDocument 设置为当前打开的。http://pastebin.com/b0fqG9v4

4

2 回答 2

5

没有被标记为已回答,所以这里有一个用于 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 ();
    }
}
于 2011-01-01T00:53:10.937 回答
3

显然,Photoshop 可以通过 Javascript 编写脚本,因此使用虚拟文件作为模型,您应该能够做您需要的事情。以下是有关 Photoshop 脚本的一些资源:

于 2010-12-27T08:26:08.613 回答