2013-10-15 46 views
1

我有一个photoshop文件和200个图像文件(PNG)。 使用photoshop作为模式,我需要生成200个新图像,其中每个图像都是放置在photoshop模式中的不同png的结果。Photoshop脚本编制:替换图像

基本上,我用photoshop的外部png文件替换photoshop中的图层。

这是可以使用Photoshop脚本自动完成的东西吗?

回答

1

基于请求,我建议使用photoshop中的变量功能。菜单 - >图像 - >变量

然后,只需选择要更改的图层并指定变量名称并选择“像素替换”行为。

在Photoshop外部,在第一行中创建一个带有变量名称的文本文件,并为每个文件命名为新行。

进入菜单 - >文件 - >导入 - >变量数据集并浏览您的文本文件。

如果你看到你的错误信息,那么一切都是正确的。

进入菜单 - >文件 - >导出 - >数据集文件和瞧!

1

是的,使用脚本,你可以做到这一点。使用源图像(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) 
    } 
} 

玩得开心。

+0

这将只是将图像粘贴到psd内的任意位置。如何指示它替换特定的图层或类似的内容..? – Rizon

+1

Waaah!你必须记住,虽然你有PSD文件在你面前,但我没有。你只给出了你想要做的很简短的描述。描述越好,其他人就越容易帮助你。注意:如果文件中有组(图层组),这不起作用 - 同样你没有指定这个。无论如何...我已经添加了一个函数,它将查找一个图层,在这个实例中,一个名为“我最喜欢的图层”的图层将改变为它所需的图层。将引号放在它周围,并且与psd文件中的引号完全相同。 –