This script is part of a larger Photoshop action we use to process our product shots after they have been edited in Photoshop. I recently discovered this part of the action (a script) had stopped working properly. It is supposed to take any image who’s longest side is larger than 2400px and reduce it to 2400px, ignoring any image who’s longest side is not larger than 2400px. But now it is running regardless of the images size which is blowing up smaller images and in the process trashing them.
We recently upgraded our Mac clients to OS 10.11 from 10.8 and during that process had to run a couple a Photoshop update as well. I would assume that one or both of these factor in. We are running Photoshop CS6 and that did not change.
#target photoshop
// get a reference to the current (active) document and store it in a variable named "doc"
doc = app.activeDocument;
// these are our values for the end result width and height (in pixels) of our image
var fWidth = 2400;
var fHeight = 2400;
// resize. if height > width (portrait-mode) AND height is larger than 2400px -- resize based on height. otherwise, resize based on width only if width is greater than 2400px
if(doc.height > 2400,"px" || doc.width > 2400,"px") {
if (doc.height > doc.width) {
doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}
}'
Any help with this would be appreciated.
2
Answers
Found a solution. Thanks to Mark Dee's comment (thanks Mark) on the syntax of the initial argument I decided that simplifying the syntax would be best.
The issue I ran into is that when giving PS a number it sets the units by the current unit of your ruler. So if the user's ruler is not set to the right unit, the script won't work. Here is my fix:
The only issue I have with it now is that it manually sets the units back to inches, I would prefer if it just put it back to "what it was previous" but I am not sure how to do that and will have to invesitgate further.
You can get and store the current rulerUnits setting in a variable which you can use to test against (and change to) the ruleUnits you need for your script and. After the script is finished you can use that same variable to restore the rulerUnits setting back to the way it was.