使用If Else语句调整Photoshop脚本图像大小

时间:2014-05-08 06:59:28

标签: photoshop

如何使用if else语句为Photoshop脚本调整图像大小。示例代码:

// 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);
}

此代码将生成此代码。如果图像宽度低于1000px,则会调整为500px(基于原始图像大小自动调整高度)。我想调整宽度和高度的特定大小。

如果图像是1000px X 500px,则此脚本会将图像大小调整为500px X 250px。我希望它将是500px X 500px。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

resizeImage的文档显示参数

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

只需更改resizeImage调用即可指定所需的高度和宽度。