【问题标题】:Photoshop Scripting: Replace an imagePhotoshop 脚本:替换图像
【发布时间】:2013-10-23 03:39:58
【问题描述】:

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

基本上,用我拥有的外部 png 文件替换 Photoshop 中的图层图像。

是否可以使用 Photoshop 脚本自动完成?

【问题讨论】:

    标签: photoshop photoshop-script


    【解决方案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)
      }
    }
    

    玩得开心。

    【讨论】:

    • 这只会将图像粘贴到 psd 内的随机位置。如何指示它替换特定图层或类似的东西..?
    • 哇!您必须记住,虽然您面前有 PSD 文件,但我没有。您只对您想要做的事情进行了非常简短的描述。描述越好,其他人就越容易帮助你。注意:如果文件中有组(层集),这将不起作用 - 同样您没有指定这一点。不管怎样...我添加了一个函数来查找一个层,在这种情况下,一个名为“我最喜欢的层”的函数将其更改为它需要的任何层。保留引号,并且与 psd 文件中的引号完全相同。
    【解决方案2】:

    根据我的要求,我建议使用 Photoshop 中的变量功能。菜单->图像->变量

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

    在 Photoshop 之外,创建一个文本文件,变量名在第一行,文件名在新行中。

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

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

    转到菜单-->文件-->导出-->数据集到文件,瞧!

    【讨论】:

      猜你喜欢
      • 2011-01-10
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 2017-10-05
      相关资源
      最近更新 更多