macos - 使用快速操作自动更改图像宽度和调整高度
问题描述
如果您有图像文件,则可以执行以下操作:
- 在 Apples Preview 应用中打开文件
- 转到:工具>调整大小...</li>
- 勾选“按比例缩放”
- 将“宽度:”中的值更改为 100 像素
这看起来像这样:
这将改变图像的宽度并自动调整高度,而不会剪切图像。
我想创建一个快速操作,它为我做这件事:将宽度更改为 100 像素并自动调整高度。
是否可以使用 Automators 快速操作编辑器来做到这一点?
解决方案
on run {input, parameters}
set targetWidth to 100
repeat with anAlias in (get contents of input)
set hfsPath to anAlias as text
try
tell application "Image Events"
launch
set anImage to open (file hfsPath)
set {w, h} to dimensions of anImage
if w > h then
scale anImage to size targetWidth
else
scale anImage to size (round (targetWidth * h / w) rounding up)
end if
save anImage with icon
close anImage
end tell
on error error_message
display dialog error_message
end try
end repeat
return input
end run
- 打开自动机
- 选择创建快速操作
- 设置“工作流在 Finder.app 中接收图像文件”
- 使用上面的内容添加运行 AppleScript 操作。
- 保存(此服务)
推荐阅读
- swift - TextField SwiftUI 之间的空间
- java - Android 应用 NullPointerException 它不应该发生在哪里?
- python - 在列表列表中循环
- spring-security - 是否可以将 keycloak 与弹簧安全一起使用?
- c++ - 如何使用 C++ STL 中的值获取地图的键
- angular - 为什么我得到 (intermediate value)(intermediate value)(intermediate value).reduce 不是函数
- c# - 在 EventLoopScheduler 中停止无限循环
- function - 我在 Pine 中声明函数时遇到赋值问题
- python - 正则表达式 Python:从数据框中的列中提取遵循模式的单词
- c++ - C++20,如何用 Clang-10 或 GCC11 编译