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

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

Explorer ,
Jun 07, 2022 Jun 07, 2022

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

TOPICS
Actions and scripting

Views

278

Translate

Translate

Report

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;

 

Votes

Translate

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

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;

 

Votes

Translate

Translate

Report

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
Explorer ,
Jun 07, 2022 Jun 07, 2022

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! 

Votes

Translate

Translate

Report

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
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

LATEST

Done!

Votes

Translate

Translate

Report

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