From: bonus on
Any users out there use Javascript for Scripting Photoshop? My
conditional is not working.

Thanks in Advance!



#target photoshop
app.bringToFront();


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


var doc = app.activeDocument;

if (doc.height > '1200px') {
fitImage (1800,300) //pixels - resolution
}
if (doc.width > '1200px') {
fitImage (1800,300) //pixels - resolution
}
else {
fitImage (900,300) //pixels - resolution
}
From: Jeremy J Starcher on
On Thu, 25 Mar 2010 10:29:47 -0700, bonus wrote:

> Any users out there use Javascript for Scripting Photoshop? My
> conditional is not working.
>
> Thanks in Advance!

I don't use the Photoshop scripting. However, had you let us know
/which/ conditional was not working, we might be able to give some help
anyways.

Reaching into my mind-reading powers, I am going to take a while guess
that your trouble is here:
> if (doc.width > '1200px') {

if (typeof doc.width === 'string') then in lexiconal sorting
'900px' > '1200px' == true

But, if you convert to an integer like this
parseInt('900px', 10) > 1200 == false




>
>
>
> #target photoshop
> app.bringToFront();
>
>
> function fitImage(newImgSize,res) {
> var doc = app.activeDocument;
> if (res == undefined) res = undefined;
> 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
> if (doc.width == doc.height) {
> doc.resizeImage(new UnitValue(newImgSize,'px'), new
> UnitValue(newImgSize,'px'), res, ResampleMethod.BICUBIC);
> }
> };
>
>
> var doc = app.activeDocument;
>
> if (doc.height > '1200px') {
> fitImage (1800,300) //pixels - resolution
> }
> if (doc.width > '1200px') {
> fitImage (1800,300) //pixels - resolution
> }
> else {
> fitImage (900,300) //pixels - resolution
> }

From: Lasse Reichstein Nielsen on
bonus <tkphoto(a)comcast.net> writes:

You need to write better error descriptions :)
In this case, what should the code do, and what does it actually do
(i.e., what do you expect, and what actually happens).
Since we don't know the intention of the code, it's at best a guess
at what part is not doing what it should.

That said:

> function fitImage(newImgSize,res) {
> var doc = app.activeDocument;
> if (res == undefined) res = undefined;

Seems wasteful to assign undefined to res just after having checked
that it is already undefined (or null).

> if (doc.width > doc.height) {

The indentation here suggests that it should be part of a branch
from the if above. However, it isn't. This might be your problem.


> var doc = app.activeDocument;
>
> if (doc.height > '1200px') {

Doing string compare is unlikely to be what you want, since it is
lexical comparison: "800px" > "1200px".
Perhaps instead use:
if (parseInt(doc.height, 10) > 1200) {

/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'

From: bonus on
Yes I admit, I was a little distract while sending the original post.

Let me clarify my goals:

To look at the pixel range within the image and see if the image is
over 1200 pixels to resize the image to 1800 pixels.
If the pixel range is under 1200 pixels then resize the image to 900
pixels.

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') {
fitImage (1800,300) //pixels - resolution
}

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

else {
fitImage (900,300) //pixels - resolution
}

From: bonus on
Thank you,

I think you may have hit a good point with your advise.


By the way the "undefined section" of my code is the script which
compares the longest side of the image. I didn't paste this area of
the code because it isn't fully written out, but it will determine
which side needs to have canvas added to square the image off.

>
> >       if (doc.width > doc.height) {
>

Thanks!