簡體   English   中英

Photoshop Script:並排合並3張圖像

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

我需要拍攝一個約500張1024x768分辨率圖像的文件夾,並將它們一次組合成三個,分辨率為3072x768。 (不是Photoshop的photomerge)

我絕不是程序員; 剛剛偶然發現了這個站點,每個人似乎都非常有幫助。 我傾向於在Photoshop中使用Java腳本可能是我最好的選擇。

我將源文件重命名為:

Image_SD_1a

圖片_SD_1b

Image_SD_1c

圖片_SD_2a

...等等...

每生成三個圖像一個,它需要以JPG格式保存到另一個文件夾中,如下所示:

圖片_001

圖片_002

...依此類推...但是我當然可以在以后進行批量重命名。

我搜索並找到了兩個接近的腳本,但是我不夠聰明,無法添加“第三”圖像步驟或更改文件名結構。

如何在Photoshop中將兩個獨特的系列圖像批量合並為單個並排圖像?

在文件夾Photoshop腳本中將文件合並在一起(並排)

很感謝任何形式的幫助!

該腳本將執行您想要的操作。 它遵循以下原則:

  • 您的所有圖像(Image_SD_1a.jpg,Image_SD_1b.jpg,Image_SD_1b.jpg)都位於同一目錄中。
  • 圖片是jpegs(將另存為Image_SD_1abc.jpg)
  • 圖像將與其他圖像保存在同一文件夾中。
  • 打開圖像A,然后運行腳本。

它不是完美的,可以改進和改進,但是很累,我的咖啡用光了。 腳本如下:

//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