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

我希望做一个photoshop动作(也许这是不可能的,任何其他应用程序的建议也会有所帮助)。我想拍摄一系列照片并使它们成为特定的方面,例如:4:3。 所以我的图像宽150像素,高200像素。我想要发生的是图像的画布宽267px,新区域填充了一定的颜色。 所以我可以想到两种可能性: 1)Photoshop动作可以做到这一点,但我必须拉出当前高度,乘以1.333333,然后将该值放在画布调整大小的宽度框中。是否可以在Photoshop操作中获得计算值? 2)其他一些应用程序内置了此功能。 任何帮助是极大的赞赏。     
已邀请:
哇,我现在(在写完答案后)看到这是很久以前的问题。 。 。那好吧。这个脚本可以解决问题。 此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);
}
    
你知道哪种语言? ImageMagick具有可以执行此操作的命令行工具,但您需要了解脚本语言才能获取值并计算新值。 对于.NET,我公司的产品DotImage Photo是免费的,可以做到这一点(需要知道C#或VB.NET)     
请注意,如果源图像具有与72不同的像素/英寸,@ user268911的接受答案可能不适合您。因为UnitValue.convert功能仅能以72 px / inch正常工作。要确保转换对于每个像素/英寸值都是正确的,请按如下所示设置baseUnit属性:
 ...
 var pixelWidth = new UnitValue (doc.width, doc.width.type);
 pixelWidth.baseUnit = UnitValue (doc.width.baseUnit, "in");
 var pixelHeight = new UnitValue (doc.height, doc.height.type);
 pixelHeight.baseUnit = UnitValue (doc.height.baseUnit, "in");
 ...
有关转换的更多详细信息,请参阅“Adobe JavaScript工具指南”中的“转换像素和百分比值”部分。     

要回复问题请先登录注册