Photoshop Action 填充图像以使其达到一定的比例

发布于 2024-10-04 15:20:39 字数 311 浏览 3 评论 0原文

我正在寻找一个 Photoshop 动作(也许这是不可能的,任何其他应用程序推荐也会有帮助)。我想拍摄一组照片并使其具有一定的宽高比,例如:4:3。

所以我有一个 150 像素宽 x 200 像素高的图像。我希望发生的是图像的画布宽度为 267px,新区域填充某种颜色。

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

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

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

非常感谢任何帮助。

I am looking to make a photoshop action (maybe this isn't possible, any other application recommendations would be helpful as well). I want to take a collection of photos and make them a certain aspect ration, ex: 4:3.

So I have an image that is 150px wide by 200px high. What I would like to happen is the image's canvas is made to be 267px wide, with the new area filled with a certain color.

So there are two possibilities I can think of:

1) Photoshop actions could do this, but I would have to pull current height, multiply by 1.333333 and then put that value in the width box of the canvas resize. Is it possible to have calculated values in Photoshop actions?

2) Some other application has this feature built in.

Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲念泪 2024-10-11 15:20:39

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

此 Photoshop 脚本将调整任何图像画布的大小,使其具有 4:5 的长宽比。您可以通过更改 arWidth 和 arHeight 来更改应用的纵横比。填充颜​​色将设置为当前背景颜色。您可以创建一个操作来打开文件,应用此脚本,然后关闭文件以执行批处理。

关闭 Photoshop。
将此 JavaScript 复制到 Photoshop 的 Presets\Scripts 文件夹中名为“Resize Canvas.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);
}

Wow, I see now (after writing the answer) that this was asked a long time ago. . . oh well. This script does the trick.

This Photoshop script will resize any image's canvas so that it has a 4:5 aspect ratio. You can change the aspect ratio applied by changing arWidth and arHeight. The fill color will be set to the current background color. You could create an action to open a file, apply this script, then close the file to do a batch process.

Shutdown Photoshop.
Copy this javascript into a new file named "Resize Canvas.jsx" in Photoshop's Presets\Scripts folder.
Start Photoshop and in the File - Scripts menu it should appear.

#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);
}
单调的奢华 2024-10-11 15:20:39

请注意,如果源图像的像素/英寸数与 72 不同,@user268911 接受的答案可能不适用于您。因为UnitValue.convert 函数仅适用于 72 像素/英寸。要确保转换对于每个像素/英寸值都是正确的,请按如下方式设置 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 工具指南

Mind that the accepted answer from @user268911 may not work for you if the source image has different pixels/inch than 72. Because the UnitValue.convert function works correctly only with 72 px/inch. To be sure the conversion is correct for ever pixel/inch value, set baseUnit property as follows:

 ...
 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");
 ...

For more details about the conversion see "Converting pixel and percentage values" section of the Adobe JavaScript Tools Guide.

梦纸 2024-10-11 15:20:39

你懂什么语言? ImageMagick 具有可以执行此操作的命令行工具,但您需要了解脚本语言才能获取值并计算新值。

对于.NET,我公司的产品DotImage Photo是免费的并且可以做到这一点(需要了解C#或VB.NET)

What languages do you know? ImageMagick has command line tools that can do this, but you'd need to know a scripting language to get the values and calculate the new ones.

For .NET, my company's product, DotImage Photo, is free and can do this (need to know C# or VB.NET)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文