简体   繁体   English

Photoshop Script:并排合并3张图像

[英]Photoshop Script: combine 3 images side-by-side

I'm needing to take a folder of about 500 1024x768 resolution images, and combine them three at a time into a solid panorama at 3072x768. 我需要拍摄一个约500张1024x768分辨率图像的文件夹,并将它们一次组合成三个,分辨率为3072x768。 (Not Photoshop's photomerge) (不是Photoshop的photomerge)

I am by no means a programmer; 我绝不是程序员; just stumbled upon this site and everyone seems very helpful. 刚刚偶然发现了这个站点,每个人似乎都非常有帮助。 I'm leaning that using a java script inside Photoshop is probably my best bet. 我倾向于在Photoshop中使用Java脚本可能是我最好的选择。

I'll rename the source files to: 我将源文件重命名为:

Image_SD_1a Image_SD_1a

Image_SD_1b 图片_SD_1b

Image_SD_1c Image_SD_1c

Image_SD_2a 图片_SD_2a

...and so on... ...等等...

One each three-image is built, it needs to save into another folder as a JPG, as: 每生成三个图像一个,它需要以JPG格式保存到另一个文件夹中,如下所示:

Image_001 图片_001

Image_002 图片_002

...and so on... But I can do a batch rename after of course. ...依此类推...但是我当然可以在以后进行批量重命名。

I searched and found these two scripts that are close, but I'm not smart enough to add a "third" image step, or change the file name structure. 我搜索并找到了两个接近的脚本,但是我不够聪明,无法添加“第三”图像步骤或更改文件名结构。

How to batch combine two unique series of images into a single side-by-side image in Photoshop? 如何在Photoshop中将两个独特的系列图像批量合并为单个并排图像?

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

Any help is very much appreciated! 很感谢任何形式的帮助!

This script will do what you want. 该脚本将执行您想要的操作。 It works on these principles: 它遵循以下原则:

  • All your images (Image_SD_1a.jpg, Image_SD_1b.jpg, Image_SD_1b.jpg) are in the same directory. 您的所有图像(Image_SD_1a.jpg,Image_SD_1b.jpg,Image_SD_1b.jpg)都位于同一目录中。
  • The images are jpegs (will be saved out as Image_SD_1abc.jpg) 图片是jpegs(将另存为Image_SD_1abc.jpg)
  • The images will be saved out in the same folder as the other images. 图像将与其他图像保存在同一文件夹中。
  • Open image A AND THEN run the script. 打开图像A,然后运行脚本。

It's not perfect, and it could be improved and made better, but tired and I'm running out of coffee. 它不是完美的,可以改进和改进,但是很累,我的咖啡用光了。 Script is as follows: 脚本如下:

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


// call the source document
var srcDoc = app.activeDocument;
var ext = getFileExtension(srcDoc);
var docPath = srcDoc.path;

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

// name the mother
var docName = srcDoc.name;

// get names for images B & C
var imageStub = getImageName(docName);
var imageB = docPath + "/" + imageStub + "b" + ext;
var imageC = docPath + "/" + imageStub + "c" + ext;

// load image B % copy it
openThisFile(imageB);
activeDocument.selection.selectAll();
activeDocument.selection.copy();
activeDocument.selection.deselect();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);


// return to image A
app.activeDocument = srcDoc;

// paste it
activeDocument.paste();
translateLayer(imageW, 0);

// do the same for C
// load image C % copy it
openThisFile(imageC);
activeDocument.selection.selectAll();
activeDocument.selection.copy();
activeDocument.selection.deselect();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

// return to image A
app.activeDocument = srcDoc;

// paste it
activeDocument.paste();
translateLayer(imageW *2, 0);


// resize canvas
srcDoc.resizeCanvas(imageW *3, imageH, AnchorPosition.MIDDLELEFT);

// flatten it
srcDoc.flatten();

// save it out
var tempName = imageStub + "abc";
saveMe(docPath, tempName, 12);

// close the new doc
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

function getImageName (astring)
{
  // Image_SD_1a.jpg
  astring += "";
  //re move extension -1
  var temp = astring.substring(0, astring.lastIndexOf("."));
  return temp.substring(0, temp.length-1);
}

function getFileExtension (astring)
{
  astring += "";
  var x = astring.substring(astring.lastIndexOf("."), astring.length-1);
  //alert(x);
  return x;
}

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

function saveMe(fPath, fname, myJpgQuality)
{
  //vegetables 
  if (!myJpgQuality) myJpgQuality = 12;

  // Set filePath and fileName to source path
  filePath = fPath + "/" + fname + ".jpg";

  var jpgFile = new File(filePath);
  jpgSaveOptions = new JPEGSaveOptions();
  jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
  jpgSaveOptions.embedColorProfile = true;
  jpgSaveOptions.matte = MatteType.NONE;
  jpgSaveOptions.quality = myJpgQuality;

  activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}

function translateLayer(dx,dy)
{
  // =======================================================
  var id2014 = charIDToTypeID( "Trnf" );
  var desc416 = new ActionDescriptor();
  var id2015 = charIDToTypeID( "null" );
  var ref287 = new ActionReference();
  var id2016 = charIDToTypeID( "Lyr " );
  var id2017 = charIDToTypeID( "Ordn" );
  var id2018 = charIDToTypeID( "Trgt" );
  ref287.putEnumerated( id2016, id2017, id2018 );
  desc416.putReference( id2015, ref287 );
  var id2019 = charIDToTypeID( "FTcs" );
  var id2020 = charIDToTypeID( "QCSt" );
  var id2021 = charIDToTypeID( "Qcsa" );
  desc416.putEnumerated( id2019, id2020, id2021 );
  var id2022 = charIDToTypeID( "Ofst" );
  var desc417 = new ActionDescriptor();
  var id2023 = charIDToTypeID( "Hrzn" );
  var id2024 = charIDToTypeID( "#Pxl" );
  desc417.putUnitDouble( id2023, id2024, dx );
  var id2025 = charIDToTypeID( "Vrtc" );
  var id2026 = charIDToTypeID( "#Pxl" );
  desc417.putUnitDouble( id2025, id2026, dy );
  var id2027 = charIDToTypeID( "Ofst" );
  desc416.putObject( id2022, id2027, desc417 );
  executeAction( id2014, desc416, DialogModes.NO );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM