4

AppleScript を使用して画像を半分にカットし、別々に保存することはできますか?

4

2 に答える 2

7

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

于 2011-10-11T19:37:36.713 に答える
2

スクリプト可能な画像編集アプリケーション (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 のものに似ています)。選択した画像編集アプリを選択し、辞書を熟読してその機能を確認してください。

于 2011-10-11T18:58:08.730 に答える