うわー、私は今(答えを書いた後)これがずっと前に尋ねられたのを見る。。。しかたがない。このスクリプトでうまくいきます。
このPhotoshopスクリプトは、4:5のアスペクト比になるように画像のキャンバスのサイズを変更します。arWidthとarHeightを変更することで、適用されるアスペクト比を変更できます。塗りつぶしの色は、現在の背景色に設定されます。ファイルを開くアクションを作成し、このスクリプトを適用してから、ファイルを閉じてバッチプロセスを実行できます。
Photoshopをシャットダウンします。
このJavaScriptを、PhotoshopのPresets\Scriptsフォルダーにある「ResizeCanvas.jsx」という名前の新しいファイルにコピーします。
Photoshopを起動すると、[ファイル]-[スクリプト]メニューに表示されます。
#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);
}