自动批处理脚本-在Photoshop中将文件名转换为文本

ina*_*ina 0 javascript photoshop adobe extendscript flash-cs5

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

文件夹1:文件混乱

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

这是被黑客入侵的代码段。我似乎无法解决的错误是如何将activeDocument设置为当前打开的文件。http://pastebin.com/b0fqG9v4

小智 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 ();
    }
}
Run Code Online (Sandbox Code Playgroud)