gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:52:08 25 4
gpt4 key购买 nike

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

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

最佳答案

您可以使用普通的 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

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

关于image - 仅将图像调整为特定宽度(AppleScript 或 Automator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30913245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com