PhotoShop中批量调整图片大小

3
我经常需要调整(很多)图像的大小为正方形,并使用PhotoShop保存它们。例如,如果一个图像是400x200,则需要调整画布大小为400x400。同样,如果一个图像是321x850,则画布大小将被调整为850x850;如果一个图像是521x250,则画布大小将被调整为521x521。
在PhotoShop中有没有一种自动完成这个繁琐任务的方法?我知道PhotoShop可以自动化记录你的操作,但这不是我想要的。如果你能指点我正确的方向,我就没有问题编写解决方案。这是可能的吗?
提前致谢。这可以节省我数小时的繁琐重复工作。

我认为你应该使用VSO Image Resizer,有时我也需要做类似的事情,你只需要将模式设置为中心即可。 - Kamil
使用JS进行脚本编写对我来说很好,谢谢。 - Xolani
4个回答

7
使用JavaScript:您可以使用这个答案来选择所选文件夹中的所有文件并循环遍历它们。在循环中,您需要像这样打开每个文件:
var doc = open(fileList[i]);

然后检查长度和宽度:

if (doc.width !== doc.height) {             // if document is not already square...
    if (doc.width > doc.height) {               // if width is greater...
        doc.resizeCanvas(doc.width, doc.width)   // use this value for both sides...
    } else {                                      // else use height for both sides...
        doc.resizeCanvas(doc.height, doc.height)      // so you always get a square.
    }
}

保存并关闭:
doc.save();
doc.close();

根据您的需求,还有doc.resizeImage()方法可供使用。

Adobe脚本指南


3

在Mac OS X中批量调整图片大小

你可以使用自带的Preview应用程序轻松地对一组图片进行批量调整大小,无需任何额外下载或昂贵的照片编辑应用程序,只需要免费的Preview应用程序即可!以下是操作步骤:

1. Select all the images you want resized and open them within Preview
2. From Preview, select the images that you want to batch resize from the drawer (Command+A will select them all)
3. Now, go to the menu labeled Tools, and then Adjust Size
4. Enter a value for what you want the new width and height to be
5. Next, navigate to the File menu and click Save All
6. All the images you selected are now resized!

这在几乎所有版本的Mac OS X中都包含了预览功能,批量调整大小愉快!

0

使用这个脚本会出错。

if (doc.width !== doc.height) {             // if document is notalready square...
     if (doc.width > doc.height) {               // if width is greater...
         doc.resizeCanvas(doc.width, doc.width)   // use this value for both sides...
     else {                                      // else use height for both sides...
         doc.resizeCanvas(doc.height, doc.height)      // so you always get a square.
     } }

代码第4行使用了不合法的else语句


你的括号闭合有误...在else语句之前应该只有一个花括号。我建议你把最后一个括号移到下一行,并保持缩进/嵌套——这有助于你发现循环不完全正确的情况。 - Henry Gibson

0
错误发生是因为第三行末尾缺少'}'。 if条件语句必须在else条件语句之前关闭。
if (doc.width !== doc.height) {                // if document is notalready square...
 if (doc.width > doc.height) {                 // if width is greater...
     doc.resizeCanvas(doc.width, doc.width)}   // use this value for both sides...
 else {                                        // else use height for both sides...
     doc.resizeCanvas(doc.height, doc.height)} // so you always get a square.
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接