首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Photoshop脚本:替换图像

Photoshop脚本:替换图像
EN

Stack Overflow用户
提问于 2013-10-15 10:54:33
回答 2查看 5.5K关注 0票数 2

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

基本上,用我有的外部png文件替换了photoshop内部图层的图像。

它是可以使用photoshop脚本自动完成的吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-05 19:11:25

根据要求,我建议在photoshop中使用变量特性。菜单->图像->变量

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

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

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

如果您看到了错误消息,那么一切都是正确的。

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

票数 1
EN

Stack Overflow用户

发布于 2013-10-15 14:51:46

是的,使用脚本可以做到这一点。使用源映像(psd),然后加载200幅图像中的每一幅,并将其放入源文件中(然后随心所欲地执行,保存文件),切换回源文件,继续遍历图像,直到全部完成为止。

代码语言:javascript
复制
// 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)
  }
}

玩得开心。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19379449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档