Copy link to clipboard
Copied
I have a javascript that creates a 3D book. If I comment out the code shown by the arrow
and scale the final file in Photoshop, it looks like this:
Note the area marked in red. If I uncomment the line to scale the book by the same 28% I used manually, it looks like this:
Any idea why I get a different result when scaled by hand vs. javascript? Thanks.
Nothing is unclear without your original file. It feels like you're using effects. If so, then with manual scaling, they are also scaled by default. If you use effects for a layer, then using DOM code you will not be able to scale them. It is necessary to use the AM version of the code in the same way as is used in Actions.
UPD
What does this script give?
...var d = new ActionDescriptor();
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), 28);
d.putBoolean(stringIDToTypeID("sca
Copy link to clipboard
Copied
Have you tried converting all the values to numbers and not having unit values as px? I've gotten odd results with some math functions if I don't make sure everything is numbers.
Copy link to clipboard
Copied
Hi Chuck. I tried using points but that didn't work either. There is only 1 layer. The image size before scaling is 828 x 1381. I want to scale it by 28% to get 231 x 386. I can't attach the file as it's 1279 x 1560 px so it will scale down.
Copy link to clipboard
Copied
try adding the below before your initial variables.
var setRule = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
Copy link to clipboard
Copied
Thanks for the suggestion. I tried this but no luck. I'll try Chuck Uebele's suggestion next.
Copy link to clipboard
Copied
Is it one layer or more? Are there any effects?
It would be best to look at your entire file. And explain exactly how you want to resize your file at the end.
Copy link to clipboard
Copied
I tried using this script and a doc size starting at 828X1381. I got an image of 232X387 using both the script and manually changing the size. 28% of 828 is 231.84, so rounded off it would be 232, which is what I got.
#target photoshop
var doc = activeDocument
doc.resizeImage(doc.width*.28,undefined,undefined,ResampleMethod.BICUBIC)
Copy link to clipboard
Copied
Hi Chuck, I have no problem having it scale 28%. My problem is scaling manually vs. using javascript. If you look at my screenshots, the file that is scaled manually has no blur in the red area. The file that uses the javascript resize has a noticeable blur in the red area.
Thanks.
Copy link to clipboard
Copied
What interpolation do you use for manual scaling?
Copy link to clipboard
Copied
The same as the javascript: BICUBIC.
Copy link to clipboard
Copied
Create a new Action and write your manual scaling in it.
Play the action on the original file.
What is the result?
If it coincides with your manual scaling, then it is advisable to take a look at your Action and script and compare them.
Your original file is also desirable.)
Copy link to clipboard
Copied
Hi r-bin, I created a new Action and played it. I get the same result as when I manually scale it. It looks correct. The action and the script look the same; scale by 28% with BICUBIC. One file is correct and one isn't.
Copy link to clipboard
Copied
What exactly the file sizes (height, width) are in pixels after the script and after manual scaling. Do they match absolutely?
Try to use in the script
activeDocument.resizeImage(UnitValue(28, "%"), null, null, ResampleMethod.BICUBIC)
and
activeDocument.resizeImage(UnitValue(28, "%"), UnitValue(28, "%"), null, ResampleMethod.BICUBIC)
What is the result?
Copy link to clipboard
Copied
Hello r-bin. I tried both ways and got the same results:
Copy link to clipboard
Copied
Nothing is unclear without your original file. It feels like you're using effects. If so, then with manual scaling, they are also scaled by default. If you use effects for a layer, then using DOM code you will not be able to scale them. It is necessary to use the AM version of the code in the same way as is used in Actions.
UPD
What does this script give?
var d = new ActionDescriptor();
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), 28);
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubic"));
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
Copy link to clipboard
Copied
Hello r-bin. You're a genius. This worked.