AppleScript を使用して画像を半分にカットし、別々に保存することはできますか?
2 に答える
ImageMagickを使用する方が簡単です。これは、左半分を として保存しinput-0.png
、右半分をとして保存しinput-1.png
ます。
convert input.png -crop 50%x100% +repage input.png
これにより、右半分が次のように保存されright.png
ます。
convert input.png -gravity east -crop 50%x100% +repage right.png
+repage
古いキャンバス サイズのメタデータを削除します。http://www.imagemagick.org/Usage/crop/を参照してください。
brew install imagemagick
またはで ImageMagick をインストールできますsudo port install imagemagick
。
スクリプト可能な画像編集アプリケーション (Photoshop など) にアクセスできない場合は、Mac OS X に付属の Image Events を使用して画像を切り取ることができます。画像の寸法を取得するには、次のようなものを使用してください...
on GetImageDimensions(TheFile) -- (file path as string) as {width, height}
try
tell application "Image Events"
launch --we have to launch Image Events before we can use it
set theImage to open TheFile
set theImageDimensions to dimensions of theImage
set theImageWidth to item 1 of theImageDimensions
set theImageHeight to item 2 of theImageDimensions
return {theImageWidth, theImageHeight}
end tell
on error
return {-1, -1} // just in case something goes wrong
end try
end GetImageDimensions
...そして、画像をトリミングするコマンドは次のように簡単です
crop pathToFile to dimensions {cropWidth, cropHeight}
たまたま Photoshop を使用している場合、切り抜きは別の方法で処理されます。
crop pathToFile bounds {cropLeft, cropTop, cropRight, cropBottom}
コマンドには他にもありますが、これらは必須パラメーターです。他のアプリケーションの実装はおそらく異なります (おそらく Apple のものに似ています)。選択した画像編集アプリを選択し、辞書を熟読してその機能を確認してください。