将文件合并(并排)在文件夹Photoshop脚本中 [英] Merging files together (side by side) in folder Photoshop scripts

查看:165
本文介绍了将文件合并(并排)在文件夹Photoshop脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做以下事情。在文件夹中设置多个png文件并设置命名约定:
1.png 1_m.png,2.png 2_m.png(依此类推)。
png文件具有相同的宽度和高度(320 x 360像素)。

I need to do the following thing. Having multiple png files in folder with a naming convention set: 1.png 1_m.png, 2.png 2_m.png (and so on). The png files have the same width and height (320 x 360 px).

现在脚本应该执行以下操作:

取文件1.png 1_m.png并创建一个新文件,其中1_m.png位于左侧,而1.png位于右侧,合并这两个在一个图层上保存它,比如1_done.png,
对文件夹中的所有文件运行此操作。

take the files 1.png 1_m.png and create a new file in which the 1_m.png is placed on the left and 1.png on the right merge those two on one layer and save it as lets say 1_done.png, run this action on all files in the folder.

这不一定是Photoshop脚本我在网上搜索过但找不到任何有用的解决方案。此处也没有任何内容,文件可能位于不同的文件夹中,这是最简单的解决方案。
我的Photoshop版本是CS5

This doesn't have to be a Photoshop script I've searched the web but couldn't find any useful solution. Also nothing is set in stone here, the files could be in different folders what ever would be the simplest solution. My Photoshop version is CS5

推荐答案

这个脚本可以做你想要的。将所有文件放在目录中,然后使用automate batch - > script运行脚本。它会在文件名中找到没有和下划线的图像,然后打开它的配对名称文件(带有_m),将它们并排放置并将_done添加到文件名中保存。

This script will do what you want. Put all the files in a directory and then run the script using automate batch -> script. It'll find an image without and underscore in the the file-name and then open it's paired name file (with "_m"), put them side by side and save it out with _done added on to the file-name.

// pref pixels
app.preferences.rulerUnits = Units.PIXELS;

//pref pixels app.preferences.rulerUnits = Units.PIXELS;

var srcDoc = app.activeDocument;

// call the current document
var srcDoc = app.activeDocument;

// set original width and height
var imageW = srcDoc.width.value;
var imageH = srcDoc.height.value;

// get the info out of the source doc
var fileName = srcDoc.name;
var docName = fileName.substring(0,fileName.length -4);
var filePath = srcDoc.path.toString();
var fileExt = fileName.substring(fileName.length -4, fileName.length);

var nameCheck = fileName.substring(0,fileName.indexOf("_"));

if (nameCheck <1)
{
   // no underscore so we need to open it's namesake
   // alert(nameCheck)
   var filePair = filePath + "/" + docName + "_m" + fileExt;
   openThisFile(filePair)
   activeDocument.selection.selectAll()
   activeDocument.selection.copy();
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
   app.activeDocument = srcDoc;
   activeDocument.resizeCanvas(imageW *2, imageH, AnchorPosition.MIDDLELEFT);
   selectRect(0, imageW, imageW*2, imageH)
   activeDocument.paste()
   activeDocument.flatten();
   var newName = filePath + "/" + docName + "_done" + fileExt
   saveMe(newName)
}
    else
    {
      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }


function openThisFile(masterFileNameAndPath)
{
 var fileRef = new File(masterFileNameAndPath)
 if (fileRef.exists)
 //open that doc
 {
    app.open(fileRef);
 }
 else
 {
    alert("error opening " + masterFileNameAndPath)
 }
}


function selectRect(top, left, right, bottom)
{
    srcDoc.selection.deselect()
    // =======================================================
    var id1 = charIDToTypeID( "setd" );
    var desc1 = new ActionDescriptor();
    var id2 = charIDToTypeID( "null" );
    var ref1 = new ActionReference();
    var id3 = charIDToTypeID( "Chnl" );
    var id4 = charIDToTypeID( "fsel" );
    ref1.putProperty( id3, id4 );
    desc1.putReference( id2, ref1 );
    var id5 = charIDToTypeID( "T   " );
    var desc2 = new ActionDescriptor();
    var id6 = charIDToTypeID( "Top " );
    var id7 = charIDToTypeID( "#Pxl" );
    desc2.putUnitDouble( id6, id7, top );
    var id8 = charIDToTypeID( "Left" );
    var id9 = charIDToTypeID( "#Pxl" );
    desc2.putUnitDouble( id8, id9, left );
    var id10 = charIDToTypeID( "Btom" );
    var id11 = charIDToTypeID( "#Pxl" );
    desc2.putUnitDouble( id10, id11, bottom );
    var id12 = charIDToTypeID( "Rght" );
    var id13 = charIDToTypeID( "#Pxl" );
    desc2.putUnitDouble( id12, id13, right );
    var id16 = charIDToTypeID( "Rctn" );
    desc1.putObject( id5, id16, desc2 );
    executeAction( id1, desc1, DialogModes.NO );
}

function saveMe(fPath)
{

// save out the image
var pngFile = new File(fPath);
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 saved png
 app.activeDocument.close()
}

这篇关于将文件合并(并排)在文件夹Photoshop脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆