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

Javascript to test an image size and change size if needed

Engaged ,
Mar 06, 2020 Mar 06, 2020

I'm trying write a script to test an open image to see if its below 1000px and if so res it up to 1000px, and also test if its above 10,000px and res it down to 10,000px. I think I would set this up as and else if statement but this does'nt work any ideas where I'm going wrong?

 

if(app.activeDocument.width.value<1000){e
  app.activeDocument.resizeImage(
                  new UnitValue(1000, "px"),
                  currentHeight,
                  currentResolution,
                  ResampleMethod.BILINEAR);
	}else if (app.activeDocument.width.value>10000){
   app.activeDocument.resizeImage(              
                  new UnitValue(10000, "px"),
                  currentHeight,
                  currentResolution,
                  ResampleMethod.BILINEAR);
  }else {}

 

TOPICS
Actions and scripting
1.3K
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 , Mar 06, 2020 Mar 06, 2020
Have you set before this code
app.preferences.rulerUnits = Units.PIXELS;
 
Translate
Adobe
LEGEND ,
Mar 06, 2020 Mar 06, 2020

If you keep currentHeight and currentResolution in variables, just remove e (at end of first line).

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
Engaged ,
Mar 06, 2020 Mar 06, 2020

When I run this it does not work as expected. If its under 1000 it scales everything to 1000 including the spreads that are around 1200px, if its over it just doesn't do anything. Not sure whats going on here. Do I need to be specific about the pixels something like <1000px

 

These are the variables.

 

var currentHeight = null;
var currentResolution = 200;

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
LEGEND ,
Mar 06, 2020 Mar 06, 2020

What is spreads?

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
Engaged ,
Mar 06, 2020 Mar 06, 2020

Sorry, these images are exports of book pages. So a single page may be 600px wide to 3000px wide, and a spread is two of those pages together. 1200px wide to potentialy over 10,000 px wide. 

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
People's Champ ,
Mar 06, 2020 Mar 06, 2020
Have you set before this code
app.preferences.rulerUnits = Units.PIXELS;
 
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
Engaged ,
Mar 06, 2020 Mar 06, 2020

Awesome, that was it. Thank you!

 

 

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
LEGEND ,
Mar 06, 2020 Mar 06, 2020

I had the same guess, but that was too obvious to suggest 🙂 btw Happy ACP activity 😉

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
Engaged ,
Mar 06, 2020 Mar 06, 2020
LATEST

Thanks, I still need lots of help but its starting to sink in.

 

 

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