仅将图像调整为特定宽度(AppleScript 或 Automator)

Resize images to specific width only (AppleScript or Automator)

我已经搜索 google.com 几个小时,试图找到执行此操作的方法,但没有答案。到处都是调整到最长的尺寸,但没有调整到指定的宽度。

在 Automator 或 AppleScript 中是否有任何方法可以将图像的大小仅调整为指定的宽度,而不仅仅是最长的尺寸?我需要我的输出图像只有一个特定的宽度(例如 200px)。

您可以使用普通的 AppleScript 和名为 sips:

的 shell 实用程序来完成此操作
    on open droppings
    repeat with everyDrop in droppings
        set originalFile to quoted form of POSIX path of (everyDrop as text)
        tell application "Finder"
            set originalName to everyDrop's name
            set imageContainer to (everyDrop's container as text)
        end tell

        set reSizedName to "200W" & originalName
        set outputPath to quoted form of POSIX path of (imageContainer & reSizedName)

        do shell script "sips --resampleWidth 200 " & originalFile & " --out " & outputPath
    end repeat
end open

on run
    display dialog "Drop some Image Files to Re-size them all to 200 pixels wide" buttons {"Aye Aye"} default button "Aye Aye"
end run

这会保留原始图像的纵横比,并将宽度调整为 200 像素。希望您能看到可以在何处进行您自己的工作流程所需的更改。

如果您想拖放包含图像的文件夹以及单个文件,请尝试将其作为 droplet:

on open droppings
    repeat with everyDrop in droppings
        if (info for everyDrop)'s folder is true then
            tell application "Finder" to set allImageFiles to everyDrop's every file
            repeat with eachFile in allImageFiles
                my SetWidthTo200(eachFile)
            end repeat
        else
            my SetWidthTo200(everyDrop)
        end if
    end repeat
end open

to SetWidthTo200(img)
    set originalFile to quoted form of POSIX path of (img as text)
    tell application "Finder"
        set originalName to img's name
        set imageContainer to (img's container as text)
    end tell
    set reSizedName to "200W" & originalName
    set outputPath to quoted form of POSIX path of (imageContainer & reSizedName)
    do shell script "sips --resampleWidth 200 " & originalFile & " --out " & outputPath
end SetWidthTo200


on run
    display dialog "Drop some Image Files to Re-size them all to 200 pixels wide" buttons {"Aye Aye"} default button "Aye Aye"
end run

仍然没有错误检查或检查来确保这些文件确实是图像文件,所以请记住这一点。

这是OSX Tips使用自动调整图像大小

的摘要
  • 打开"Automator"
  • 文件 > 新建 > 服务
  • 设置:
    • 已选择收到的服务:"image files"
    • 在"Finder"
  • 在左窗格中,找到名为 "Get Selected Finder Items"
  • 的操作
  • 下一步寻找行动"Scale Images"
  • 如果你想替换原来的,当它询问时选择"Don’t Add" "would you like to add a Copy Finder Items action",否则,选择添加
  • 为了能够在缩放前选择最高像素,点击结果右边的选项,勾选 "show this action when the workflow run"