Scripting Conditional Bug

  • 1
  • Problem
  • Updated 10 months ago
So I created a script that extends or contracts a canvas by a pixel if the rounding that photoshop used is off by a pixel. For instance if something is ratio cropped at 3:4 and then sized down to be 1800 x 2400 sometimes the rounding will be off and the image will be 1799 x 2400.
I successfully made a script to fix the height if it is off by one pixel but when I use the same logic for the width it does not work. Interestingly if the canvas is of by more than a pixel it will work, so that tells me that it is a photoshop bug.

here is the function that works
 
function extend() {
var doc = app.activeDocument;
var width = activeDocument.width;
var height = activeDocument.height;


    if (height < 2400) {
        doc.resizeCanvas(width, height + 1, AnchorPosition.TOPCENTER);
    }   
     else if (height > 2400) {
         doc.resizeCanvas(width, height - 1, AnchorPosition.TOPCENTER); 
     }

    else {
   
    }          
}
           
extend();

and here is the one that doesnt work unless its off by more than a pixel

function extendWidth() {
    var doc = app.activeDocument;
    var width = activeDocument.width;
    var height = activeDocument.height;
   
    alert(width);
   
        if (width < 1800) {
            doc.resizeCanvas(width + 1, height, AnchorPosition.MIDDLECENTER);   
        }   
           
}
       
extendWidth();
Photo of Vasily Sidorenko

Vasily Sidorenko

  • 1 Post
  • 0 Reply Likes

Posted 10 months ago

  • 1

Be the first to post a reply!