From: Jeremy J Starcher on


On Thu, 25 Mar 2010 11:46:42 -0700, bonus wrote:

> I believe the problem may be in the following area, but I attached the
> whole script so you can see the function.
>
> if (doc.height > '1200px') {

Both Lasse Reichstein and I address that very issue in our previous posts.
From: bonus on
Unfortunately I am receiving the same results. When the images
process, regardless of size, the images are sizing to 900 pixels.



var doc = app.activeDocument;

if (parseInt(doc.height, 10) > '1200px')
{
fitImage (1800,300) //pixels - resolution
}

if (parseInt(doc.height, 10) > '1200px')
{
fitImage (1800,300) //pixels - resolution
}

else
{
fitImage (900,300) //pixels - resolution
}
From: Jeremy J Starcher on
On Thu, 25 Mar 2010 12:03:00 -0700, bonus wrote:

> Unfortunately I am receiving the same results. When the images process,
> regardless of size, the images are sizing to 900 pixels.

Works as coded then. *Grin*

> if (parseInt(doc.height, 10) > '1200px') {

Now you are comparing an integer (the result of "parseInt(doc.height,
10)") against a string value '1200px'.

Look at the example I gave you:
>> But, if you convert to an integer like this
>> parseInt('900px', 10) > 1200 == false

You'll note I compare integer against integer.

Your other code stood a chance of resizing the image twice, once for the
height and the other time for the width.

I would write your code like this:

var doc = app.activeDocument;

if (
(parseInt(doc.height, 10) > 1200) ||
(parseInt(doc.width, 10) > 1200)
)
{
fitImage (1800,300) //pixels - resolution
}
else
{
fitImage (900,300) //pixels - resolution
}


From: TK on
Just an FYI, I have the solution now.

Thanks for all the help!


#target photoshop
app.bringToFront();

function fitImage(newImgSize,res) {
var doc = app.activeDocument;
if (doc.width > doc.height) {doc.resizeImage(new
UnitValue(newImgSize,'px'), undefined, res, ResampleMethod.BICUBIC);}
else if (doc.width < doc.height) {doc.resizeImage(undefined, new
UnitValue(newImgSize,'px'), res, ResampleMethod.BICUBIC);}
else (doc.width == doc.height) {doc.resizeImage(new
UnitValue(newImgSize,'px'), new UnitValue(newImgSize,'px'), res,
ResampleMethod.BICUBIC);}
}

var doc = app.activeDocument;

if (doc.height.as("px") > 1200){fitImage (1800,300);}
else if (doc.width.as("px") > 1200){fitImage (1800,300);}
else {fitImage (900,300);}