哇,我现在看到(在写完答案之后)这是很久以前被问到的。. . 那好吧。这个脚本可以解决问题。
此 Photoshop 脚本将调整任何图像画布的大小,使其具有 4:5 的纵横比。您可以通过更改 arWidth 和 arHeight 来更改应用的纵横比。填充颜色将设置为当前背景颜色。您可以创建一个操作来打开文件,应用此脚本,然后关闭文件以执行批处理。
关闭 Photoshop。
将此 javascript 复制到 Photoshop 的 Presets\Scripts 文件夹中名为“Resize Canvas.jsx”的新文件中。
启动 Photoshop 并在 File - Scripts 菜单中出现。
#target photoshop
main ();
function main ()
{
if (app.documents.length < 1)
{
alert ("No document open to resize.");
return;
}
// These can be changed to create images with different aspect ratios.
var arHeight = 4;
var arWidth = 5;
// Apply the resize to Photoshop's active (selected) document.
var doc = app.activeDocument;
// Get the image size in pixels.
var pixelWidth = new UnitValue (doc.width, doc.width.type);
var pixelHeight = new UnitValue (doc.height, doc.height.type);
pixelWidth.convert ('px');
pixelHeight.convert ('px');
// Determine the target aspect ratio and the current aspect ratio of the image.
var targetAr = arWidth / arHeight;
var sourceAr = pixelWidth / pixelHeight;
// Start by setting the current dimensions.
var resizedWidth = pixelWidth;
var resizedHeight = pixelHeight;
// The source image aspect ratio determines which dimension, if any, needs to be changed.
if (sourceAr < targetAr)
resizedWidth = (arWidth * pixelHeight) / arHeight;
else
resizedHeight = (arHeight * pixelWidth) / arWidth;
// Apply the change to the image.
doc.resizeCanvas (resizedWidth, resizedHeight, AnchorPosition.MIDDLECENTER);
}