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

时间:2015-06-18 10:47:24

标签: image macos applescript image-resizing automator

我一直在搜索google.com几个小时试图找到一种方法来做到这一点,但没有答案。无处不在调整大小,但没有任何关于仅调整指定宽度的内容。

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

2 个答案:

答案 0 :(得分:4)

您可以使用普通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像素即可。希望您能看到自己的工作流程所需的更改位置。

如果要删除图像文件夹以及单个文件,请将其作为一个小滴:

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

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

答案 1 :(得分:0)

以下是OSX Tips使用automator调整图片大小的摘要

  • 打开" Automator"
  • 文件>新>服务
  • 设置:
    • 已选择服务:"图像文件"
    • in" Finder"
  • 左侧窗格中的
  • ,找到名为"获取选定的Finder项目"
  • 的操作
  • 接下来寻找行动"缩放图像"
  • 如果您想更换原件,请选择"不要添加"什么时候问 "是否要添加“复制查找器项目”操作"否则,请选择添加
  • 为了能够在缩放前选择最高像素,请单击结果右侧的选项,勾选 "在工作流程运行"
  • 时显示此操作