image - Photoshop Action 对图像进行一定比例的填充

标签 image image-processing image-manipulation photoshop photoshop-script

我正在寻找一个 photoshop Action (也许这是不可能的,任何其他应用程序推荐也会有所帮助)。我想拍摄一组照片并使它们具有特定的纵横比,例如:4:3。

所以我有一个 150 像素宽 x 200 像素高的图像。我想要的是图像的 Canvas 宽度为 267 像素,新区域填充了某种颜色。

所以我能想到的有两种可能:

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

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

非常感谢任何帮助。

最佳答案

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

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

关闭 Photoshop。
将此 javascript 复制到 Photoshop 的 Presets\Scripts 文件夹中名为“Resize Canvas.jsx”的新文件中。
启动 Photoshop,它应该出现在"file"-“脚本”菜单中。

#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);
}

关于image - Photoshop Action 对图像进行一定比例的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4307691/

相关文章:

python - 通过python将目录中的图片发布到tumblr

java - 如何在没有ImageView的TextView中间添加图像到TextView

c# - 如何使用 C# 以低分辨率形式提供高分辨率图像

c++ - 哪个开源图片库支持最多的文件格式可以用于商业应用

css - 如何在迷你固定菜单中显示黑色标志?

image-processing - Windows Phone 8.1 - 将文本添加到图像

c++ - 盲解卷积算法题

python-3.x - PIL.ImageEnhance 增强颜色、亮度和对比度功能的公式是什么?

image - 图像的结构如何

css - 使用 CSS 过滤器模拟 Photoshop 的 "Color Overlay"?