Mobile app version of vmapp.org
Login or Join
Miguel516

: Add a conditional line to existing script I've got this script from an earlier question and answer (specific resize layer action) Many thanks to SQW! (function (){ var startRulerUnits =

@Miguel516

Posted in: #AdobePhotoshop #PhotoshopScripting #Script

I've got this script from an earlier question and answer (specific resize layer action) Many thanks to SQW!

(function (){
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var bounds = activeDocument.activeLayer.bounds;
var width = bounds[2].value - bounds[0].value;
var newSize = (100 / width) * 550;
activeDocument.activeLayer.resize(newSize, newSize, AnchorPosition.BOTTOMLEFT);
app.preferences.rulerUnits = startRulerUnits;
})();


However, is it possible for the script to only run when the layer that needs to be resized is, for example, greater than 550px? I am a complete noob when it comes to scripting, and I've tried adding in an "if" function but I just don't understand how it works...

Many thanks.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Miguel516

1 Comments

Sorted by latest first Latest Oldest Best

 

@Miguel516

Thanks to SuperMerlin over at the adobe forums, he has given me the answer.

(function (){
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var bounds = activeDocument.activeLayer.bounds;
var width = bounds[2].value - bounds[0].value;
if(width > 550){
var newSize = (100 / width) * 550;
activeDocument.activeLayer.resize(newSize, newSize, AnchorPosition.BOTTOMLEFT);
}
app.preferences.rulerUnits = startRulerUnits;
})();

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme