自动批处理脚本-在Photoshop中将文件名转换为文本 [英] Automate Batch Script - Convert filenames to text in Photoshop

查看:637
本文介绍了自动批处理脚本-在Photoshop中将文件名转换为文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do you convert each filename of a bunch of files, each to a text layer (and save) in Photoshop?

文件夹1:文件混乱

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

Folder 2: Nearly the same files, but each with its filename plastered onto its image

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

Here is a hacked up snippet. The error that I can't seem to get by is how to set the activeDocument to the currently open one. http://pastebin.com/b0fqG9v4

推荐答案

未被标记为已回答,因此,这是CS的javascript示例(也应在更高版本上使用),以防有人在意这样的事情.这将打开源文件夹中的每个图像文件,并添加一个新的文本层.将文件名设置为文本层的内容,然后将新文件保存到输出位置.

Hasn't been marked as answered so here's a javascript example for CS (and should work on later versions too) in case anyone cares for such a thing. This opens each image file in a source folder and adds a new text layer. The name of the file is set as the content of the text layer, then the new file is saved to an output location.

它并没有真正尝试使图像上的文字合适,这当然是可能的,但是很复杂.

It does not really try to fit the text on the image, that's certainly possible but complicated.

如果在打开的文件中嵌入的配置文件与工作色彩空间不匹配时,如果将颜色管理设置为警告您,则会出现配置文件不匹配对话框.您可以设置您的首选项来自动处理这种情况.

If you have color management set to warn you when opening a file with an embedded profile that doesn't match the working color space you will get a profile mismatch dialog. You could set your preferences handle such a situation automatically.

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 ();
    }
}

这篇关于自动批处理脚本-在Photoshop中将文件名转换为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆