How to obtain the largest value of width and/or height of two open images?
Re: Photoshop CS6, ver 13.0.1 (x32) on Win 7 SP1 (64-bit) 16gB RAM
My Photoshop workflow deals with repeatedly editing sets of two images of an irregularly shaped object centered on a white background. Upon completion of the edits, each canvas needs to be cropped, then both resized to square canvas of the same dimensions.
The question I have is the last step: How do I determine the largest single dimension to use as px width, px height when squaring the two open images?
The following script seems to work, but I'm not sure if I am correctly selecting the active documents. Is app.activeDocument = app.documents[0] always the document currently being edited? And app.activeDocument = app.documents[1] the document not active !?
I'm a VBA/VB.Net programmer with no experience in Javascript. I will greatly appreciate expert opinions on the following, my first attempt at a Photoshop script.
#target photoshop
<menu>automate</menu>
//save the current setting
var savedRuler= app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
//set background to white
var backgroundC = new SolidColor();
backgroundC.rgb.red = 255;
backgroundC.rgb.green = 255;
backgroundC.rgb.blue = 255;
backgroundColor = backgroundC;
//get max dimension of first image
app.activeDocument = app.documents[0] // set to first image
var h = app.activeDocument.height;
var w = app.activeDocument.width;
var maxDim = w;
if(h>w) maxDim = h;
//measure second image then get the max dimension of both images
app.activeDocument = app.documents[1] // set to second image
var h2 = app.activeDocument.height;
var w2 = app.activeDocument.width;
if(w2>maxDim) maxDim = w2;
if(h2>maxDim) maxDim = h2;
//resize second image
app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER);
//resize first image
app.activeDocument = app.documents[0] // set to first image
app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER);
//clean up
app.preferences.rulerUnits = savedRuler;
