Skip to main content
April 15, 2016
Answered

Have a layer resize script, but need it to work when layer is great than 550px

  • April 15, 2016
  • 2 replies
  • 398 views

Hi,

I've luckily found a script that does a layer resize just what was needed. Only thing is, I want the script to only deploy if that current layer is greater than 550px - existing code for the script is below:

(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; 

})();

If anyone can explain how I can use an If function, would be much appreciated!

Many thanks in anticipation.

This topic has been closed for replies.
Correct answer SuperMerlin
(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;   
})(); 

2 replies

April 15, 2016

Thank you - I really appreciate the help - works perfectly!

SuperMerlin
SuperMerlinCorrect answer
Inspiring
April 15, 2016
(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;   
})();