[Automator & AppleScript] Automator: AppleScript の ImageEvents で画像をリサイズする

crop, rotate などもできるそう。

[markdown]
以前に `sips` コマンドで実現した画像のリサイズを、AppleScript 内でできないか調べていて知りました。

> * [Automatorとsips、ImageOptimをつかって画像を変換する方法 | deadwood](https://www.d-wood.com/blog/2013/04/26_3437.html)

## 最も長い辺を指定サイズにリサイズする

> * [AppleScript: Image Events](http://www.macosxautomation.com/applescript/imageevents/04.html)

targetItems という配列(list)に格納している画像を、maxpxl で指定したサイズにリサイズ(scale)処理する。

“`prettyprinted
tell application “Image Events”
launch
repeat with this_file in targetItems
set this_image to open this_file
scale this_image to size maxpxl
save this_image with icon
close this_image
end repeat
end tell
“`

`scale foo to size` 指定で、`sips -Z` と同じ振る舞いをしてくれる。
crop, rotate など他の命令もある。

> * [鳶嶋工房 / AppleScript / Dictionary / ImageEvents(目次)](http://tonbi.jp/AppleScript/Dictionary/ImageEvents/contents.html)

## 画像の縦横サイズを求める

ファイルを open した後に、`dimensions of` で取得できる。

“`prettyprinted
set this_image to open this_file
copy dimensions of this_image to {W, H}
close this_image
“`

## 補遺

アクション「Quartz コンポジションフィルタをイメージファイルに適用」のシャープを、AppleScript から使いたかったのですが分かりませんでした。
`quartz composition filter applescript` あたりで調べた。
ご存じの方いましたら、ぜひ教えて下さい。
[/markdown]