Photoshop动作来填充图像以达到一定的比例

RHo*_*ter 2 photoshop image-manipulation image image-processing photoshop-script

我希望做一个photoshop动作(也许这是不可能的,任何其他应用程序的建议也会有所帮助).我想拍摄一系列照片并使它们成为特定的方面,例如:4:3.

所以我的图像宽150像素,高200像素.我想要发生的是图像的画布宽267px,新区域填充了一定的颜色.

所以我可以想到两种可能性:

1)Photoshop动作可以做到这一点,但我必须拉出当前高度,乘以1.333333,然后将该值放在画布调整大小的宽度框中.是否可以在Photoshop操作中获得计算值?

2)其他一些应用程序内置了此功能.

任何帮助是极大的赞赏.

小智 7

哇,我现在(在写完答案后)看到这是很久以前的问题...那好吧.这个脚本可以解决问题.

此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);
}
Run Code Online (Sandbox Code Playgroud)