Copy link to clipboard
Copied
Hey! First time posting here, so please let me know if any additonal information is neeeded!
I am looking for any advice on a script to resize an image to the nearest 50 pixels. All of the images I work on are square. In order to be succesfully uploaded to the website they are meant for; the images have to be sized in increments of 50px with a max size of 2000px X 2000px and a minimum size of 600px by 600px. For example an image that is 999px by 999px would fail to upload, but an image that is 950px x 950px would upload just fine. I already have a script to crop to a square based on selection, so making the images square is not an issue at all. Therefore the input for the image size could be based on any variable of the image dimension. My coding expierience is limited so I wanted to check here before I spend countless hours trying to write the script on my own.
Essentially, I think the script would be something of
If image dimension is x, and x<=649, then resize image to 600px X 600px
If image dimension is x, and 649<x<699, then resize image to 650px X 650px
If image dimension is x, and 699<x<749, then resize image to 650px X 650px
...
If image dimension is x, and 1900<x<=1950, then resize image to 2000px X 2000px
If image dimension is x, and 1950<=x, then resize image to 2000px X 2000px
and then repeat for every size.
If someone could help me with one size I would be more than happy to do the rest on my own!
Thanks!
Justin
This is it?
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
doc.resizeImage(Math.floor(doc.width/50)*50);
app.preferences.rulerUnits = old_units;
Copy link to clipboard
Copied
This is it?
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
doc.resizeImage(Math.floor(doc.width/50)*50);
app.preferences.rulerUnits = old_units;
Copy link to clipboard
Copied
That was much simplier way to write the script than I was writing...thank you for saving me a lot of time!
Copy link to clipboard
Copied
I will just have to set a lower and higher bound for 600 and 2000 I think!
Copy link to clipboard
Copied
@J.C.C.1 – If the answer from r-bin is correct, please mark it as the correct answer.
Copy link to clipboard
Copied
Done!