【发布时间】:2013-10-23 03:39:58
【问题描述】:
我有一个 Photoshop 文件和 200 个图像文件 (png)。 使用 photoshop 作为模式,我需要生成 200 张新图像,其中每张图像是放置在 photoshop 模式中的不同 png 的结果。
基本上,用我拥有的外部 png 文件替换 Photoshop 中的图层图像。
是否可以使用 Photoshop 脚本自动完成?
【问题讨论】:
标签: photoshop photoshop-script
我有一个 Photoshop 文件和 200 个图像文件 (png)。 使用 photoshop 作为模式,我需要生成 200 张新图像,其中每张图像是放置在 photoshop 模式中的不同 png 的结果。
基本上,用我拥有的外部 png 文件替换 Photoshop 中的图层图像。
是否可以使用 Photoshop 脚本自动完成?
【问题讨论】:
标签: photoshop photoshop-script
是的,通过脚本,您可以做到这一点。使用源图像(psd)然后加载 200 个图像中的每一个并将其放入源文件中(然后做任何你想做的事情,保存文件)切换回源文件并继续循环图像直到全部完毕。
// must have source psd open to start with.
//pref pixels
app.preferences.rulerUnits = Units.PIXELS;
// call the source document
var srcDoc = app.activeDocument;
var inFolder = Folder.selectDialog("Please select folder to process");
if (inFolder != null)
{
var fileList = inFolder.getFiles(/\.(png)$/i);
}
// main loop starts here
for(var i = 0; i < fileList.length; i++)
{
// load the frames one by one
var doc = open(fileList[i]);
var tempImage = app.activeDocument.name;
//select all
activeDocument.selection.selectAll()
//copy image
activeDocument.selection.copy();
//close that document without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// select the source image
activeDocument = srcDoc;
getMeThisLayer("my favourite layer")
//paste
app.activeDocument.paste();
//deselect all
activeDocument.selection.deselect()
var filePath = srcDoc.path + "/" + tempImage;
// Flatten the image
activeDocument.flatten();
// save out the image
var pngFile = new File(filePath);
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1;
activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);
// close that save png
app.activeDocument.close()
}
function getMeThisLayer(aLayerName)
{
try
{
// try to find the layer
app.activeDocument.activeLayer = app.activeDocument.layers.getByName(aLayerName)
return
}
catch(e)
{
//Whoops can't find layer
alert("Can't find layer " + aLayerName + "\n" + e)
}
}
玩得开心。
【讨论】:
根据我的要求,我建议使用 Photoshop 中的变量功能。菜单->图像->变量
然后只需选择要更改的图层并分配变量名称并选择“像素替换”行为。
在 Photoshop 之外,创建一个文本文件,变量名在第一行,文件名在新行中。
转到菜单-->文件-->导入-->变量数据集并浏览您的文本文件。
如果你看到你的错误信息,那么一切都是正确的。
转到菜单-->文件-->导出-->数据集到文件,瞧!
【讨论】: