是否可以编写脚本来将每个图像调整为最接近的整数(例如,如果原始图像为791x1265px,则可以将其调整为800x1300px)
谢谢!
答案 0 :(得分:1)
相当简单的小脚本可以做到:)享受
注意:您有两种脚本选择;在运行脚本之前,请使用静态基值(默认值),或者如果您想在每次运行时添加提示,请在var base行下方取消注释并在var base行中添加注释:)希望这就是您想要的内容:
//get Original Ruler Units;
var origRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
//get Active document scales
var origWidth = app.activeDocument.width;
var origHeight = app.activeDocument.height;
//define base
var base = 100; //change your base like 10;100 etc; use below code to make a prompt on each run;
//var base = prompt("Enter Your Base number",""); //use this code if you want prompt for each run . uncomment by rermoving first two "//"
//magical Mathematics XD
var roundWidth = Math.ceil(origWidth / base) * base;
var roundHeight = Math.ceil(origHeight / base) * base;
//resize canvas
app.activeDocument.resizeCanvas (roundWidth, roundHeight);
//Restores Original Ruler Units;
app.preferences.rulerUnits = origRuler;
编辑:更新了脚本以避免标尺单位发生冲突,并根据@Sergey建议将Math.round更改为Math.ceil!