You could try this: // combine jpgs from a folder into images by twos; // identically named files are replaced without promting; // if selected files are open they get closed without promting; // 2011, use it at your own risk; #target photoshop // select a folder; var theFolder = Folder.selectDialog ("select folder"); if (theFolder) { // get the files; var theFolderFiles = retrieveJPGs (theFolder, []); // if more than one jpg is in the folder; if (theFolderFiles.length > 1) { // change pref; var originalRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; // jpg options; var jpegOptions = new JPEGSaveOptions(); jpegOptions.quality = 9; jpegOptions.embedColorProfile = true; jpegOptions.matte = MatteType.NONE; // do the operation; for (var m = 0; m < theFolderFiles.length / 2; m++) { // create file; var myDocument = app.documents.add(new UnitValue(590, "px"), new UnitValue(440, "px"), 300, "new", NewDocumentMode.RGB, DocumentFill.WHITE, 1, BitsPerChannelType.EIGHT, "sRGB IEC61966-2.1"); // get first image; var doc1 = scaleInto(myDocument, theFolderFiles[m * 2], 290, 440); doc1.translate(UnitValue(doc1.bounds[0] * (-1), "px"), UnitValue(0, "px")); var theName = File(theFolderFiles ).name.slice(0, -4); // get second image; if (m * 2 + 1 < theFolderFiles.length) { var doc2 = scaleInto(myDocument, theFolderFiles[m * 2 + 1], 290, 440); doc2.translate(UnitValue(myDocument.width - doc1.bounds[3], "px"), UnitValue(0, "px")); theName = theName.concat("_"+File(theFolderFiles[m * 2 + 1]).name.slice(0, -4)); }; //save jpg as a copy: myDocument.saveAs((new File(theFolder+"/mont_"+theName+".jpg")),jpegOptions,true); myDocument.close(SaveOptions.DONOTSAVECHANGES) }; // reset; app.preferences.rulerUnits = originalRulerUnits; alert ("done") } }; ////// scale ////// function scaleInto (myDocument, myPath, theWidth, theHeight) { var theDoc = app.open(File(myPath)); // flatten; theDoc.flatten(); // convert to same space as container document; theDoc.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true); // scale; if (theDoc.width / theDoc.height >= theWidth / theHeight) { var theFactor = new UnitValue (theHeight * 100 / theDoc.height, "%"); } else { var theFactor = new UnitValue (theWidth * 100 / theDoc.width, "%"); }; theDoc.resizeImage(theFactor, theFactor, myDocument.resolution, ResampleMethod.BICUBICSHARPER); theDoc.resizeCanvas(theWidth, theHeight, AnchorPosition.MIDDLECENTER); // copy layer to container document; var theLayer = theDoc.layers[0].duplicate(myDocument, ElementPlacement.PLACEATBEGINNING); theDoc.close(SaveOptions.DONOTSAVECHANGES); return theLayer }; ////// get from subfolders ////// function retrieveJPGs (theFolder, theFiles) { if (!theFiles) {var theFiles = []}; var theContent = theFolder.getFiles(); for (var n = 0; n < theContent.length; n++) { var theObject = theContent ; if (theObject.constructor.name == "Folder") { theFiles = retrieveJPGs(theObject, theFiles) }; if (theObject.name.slice(-4) == ".jpg" || theObject.name.slice(-4) == ".JPG") { theFiles = theFiles.concat(theObject) } }; return theFiles };
... View more