Skip to main content
Giallo
Participating Frequently
September 18, 2018
Answered

Conditional Image Size

  • September 18, 2018
  • 1 reply
  • 1264 views

HeyGuys I have this script that I'm realizing for adobe photoshop which will create an artistic picture from a photo. The starting image must have at least one of the sizes of 3000px so that the effects taken from the Filter Gallery are consistent for all the photos.

The script I have down here works but the only problem is that for images bigger than 3000px he will resize them: I need a part at some point which says "if >3000 pixels then don't do anything" because I want the software to Increase the Image Size only in the case both height and width are < to 3000 pixels

#target photoshop

doc = app.activeDocument;

// setting the ruler unit to pixels

app.preferences.rulerUnits = Units.PIXELS;

// these are our values for the end result width and height (in pixels) of our image

var fWidth = 3000;

var fHeight = 3000;

if(doc.height < 3000 || doc.width < 3000) {

if (doc.height > doc.width) {

    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);

    }

else {

    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);

    }

}

This topic has been closed for replies.
Correct answer frmorel

Not sure to understand, but your script actually don't do anything if doc.height > 3000 or doc.width > 3000.

To be accurate, you should write:

if(doc.height <= 3000 && doc.width <= 3000) {

1 reply

frmorelCorrect answer
Inspiring
September 18, 2018

Not sure to understand, but your script actually don't do anything if doc.height > 3000 or doc.width > 3000.

To be accurate, you should write:

if(doc.height <= 3000 && doc.width <= 3000) {

Giallo
GialloAuthor
Participating Frequently
September 18, 2018

exactly! my script shouldn't do anything if height or width > 3000 but it still does it.

However with your line it doesn't do it so maybe it was just a syntax error. Thank you very much sir!

Geppetto Luis
Legend
September 19, 2018

No, I understand what you need

this script allows you to bring up to 3000px

the lower or upper images this value.

var startRulerUnits = app.preferences.rulerUnits;

var startTypeUnits = app.preferences.typeUnits ;

var startDisplayDialogs = app.displayDialogs;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

app.displayDialogs = DialogModes.NO; 

 

var Document =app.activeDocument;

var Dimension = 3000;

var h = Document.height;

var w = Document.width;

     if (h > w) {

         Document.resizeImage(null,Dimension,null,ResampleMethod.BICUBIC);

     }

     else {

         Document.resizeImage(Dimension,null,null,ResampleMethod.BICUBIC);

     }

app.preferences.rulerUnits = startRulerUnits;

app.preferences.typeUnits = startTypeUnits;

app.displayDialogs = startDisplayDialogs;