Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using a photoshop script to resize my image to the nearest 50px.

Participant ,
Jun 07, 2022 Jun 07, 2022

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

TOPICS
Actions and scripting
973
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jun 07, 2022 Jun 07, 2022

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;

 

Translate
Adobe
People's Champ ,
Jun 07, 2022 Jun 07, 2022

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;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 07, 2022 Jun 07, 2022

That was much simplier way to write the script than I was writing...thank you for saving me a lot of time! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 07, 2022 Jun 07, 2022

I will just have to set a lower and higher bound for 600 and 2000 I think!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2022 Jun 07, 2022

@J.C.C.1 – If the answer from r-bin is correct, please mark it as the correct answer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 07, 2022 Jun 07, 2022
LATEST

Done!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines