Question

How to do Photoshop script for image resizing with if else statement. Example code:

// get a reference to the current (active) document and store it in a variable named "doc"
doc = app.activeDocument;  

// change the color mode to RGB.  Important for resizing GIFs with indexed colors, to get better results
doc.changeMode(ChangeMode.RGB);  

// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 500;
var fHeight = 500;

// do the resizing.  if height > width (portrait-mode) resize based on height.      otherwise, resize based on width
if (doc.width < "1000px") {
    doc.resizeImage(null,UnitValue(fWidth,"px"));
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

This code will generate this. If width of image below than 1000px, it will resize to 500px (height auto based on original image size). I want to resize with specific size for width and height.

If images is 1000px X 500px, this script will resize image to 500px X 250px. I want it will be 500px X 500px. How can I do this?

Était-ce utile?

La solution

The documentation for resizeImage shows the parameters are

resizeImage([width][, height][, resolution][, resampleMethod])

so simply change your resizeImage call to specify the height and width you want.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top