Riz*_*zon 2 photoshop photoshop-script
我有一个 Photoshop 文件和 200 个图像文件 (png)。使用 Photoshop 作为图案,我需要生成 200 张新图像,其中每个图像都是放置在 Photoshop 图案中的不同 png 的结果。
基本上,用我拥有的外部 png 文件替换 Photoshop 内图层的图像。
这是可以使用 Photoshop 脚本自动完成的事情吗?
是的,通过脚本,您可以做到这一点。使用源图像 (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)
}
}
Run Code Online (Sandbox Code Playgroud)
玩得开心。