Photoshop Script: Mehrere Bilder formatabhängig in ein Bild zusammen setzen

Setzt mehrere geöffnete Bilder in ein Bild zusammen, abhängig vom Format (breit/hoch).

//#####################################################################
//
//  Crop all open images and merge together in one image dependent size
//  Photoshop Script (CS2, tested on PC) 
//
//#####################################################################

// save the current preferences & settings
var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
var startDisplayDialogs = app.displayDialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO

// main script
var docs = app.documents;
var openDocs = docs.length;

// crop all open images from border
var cropSize = prompt('Crop from border (in pixel).', '');

for (var i=0; i<openDocs; i++) {

	app.activeDocument = docs[i];
	app.activeDocument.changeMode(ChangeMode.RGB);

	// don't crop if no value or image is smaller
	if (cropSize != '' && cropSize > 0 && 
		cropSize < app.activeDocument.width && 
		cropSize < app.activeDocument.height) { 
			cropWidthFromBorder(cropSize);
	}
}

// resize canvas on first image dependent on image size
var pano;
app.activeDocument = docs[0];

if(app.activeDocument.width > app.activeDocument.height) {
	pano = true;
	app.activeDocument.resizeCanvas(app.activeDocument.width, 
		app.activeDocument.height * openDocs, AnchorPosition.TOPLEFT);
}
else {
	pano = false;
	app.activeDocument.resizeCanvas(app.activeDocument.width * openDocs, 
		app.activeDocument.height, AnchorPosition.TOPLEFT);
}

// put all images into first image
for (var j=1; j<openDocs; j++) {

	app.activeDocument = docs[j];
	app.activeDocument.activeLayer.copy();
	app.activeDocument = docs[0];

	if(pano) {
		setSection(0, app.activeDocument.height/2, 
			app.activeDocument.width, app.activeDocument.height);
	}
	else {
		setSection(app.activeDocument.width/2, 0, 
			app.activeDocument.width, app.activeDocument.height);
	}

	app.activeDocument.paste();
}

app.activeDocument.flatten();

// close all open images except the first
//if (confirm('Close all images except the first one?')) {
	for (var x=1; x<openDocs; x++) {
		docs[x].close(SaveOptions.DONOTSAVECHANGES)
	}
//}

// restore settings
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;

//alert("Done!");

//####################################################################

function cropWidthFromBorder(cropWidth) { 
	app.activeDocument.crop(Array(cropWidth,
		cropWidth,
		app.activeDocument.width - cropWidth,
		app.activeDocument.height - cropWidth));
}

function setSection(left, top, width, height) {
	var selRegion = Array(
		Array(left, top),
		Array(left + width, top),
		Array(left + width, top + height),
		Array(left, top + height),
		Array(left, top));
	app.activeDocument.selection.select(selRegion);
}