sipsには画像をリサイズするオプションが複数あり、縦横比を保つかどうかで使い分ける。

参考: 【sips】コマンドで画像のプロパティ情報を確認する

-zで高さ・幅を指定してリサイズする

-z <高さ> <幅>で、指定したピクセルサイズにリサイズする。引数の順序は高さ・幅の順である点に注意する。

$ sips -z 300 400 photo.png --out resized.png
$ sips -g pixelWidth -g pixelHeight resized.png
/path/to/resized.png
  pixelWidth: 400
  pixelHeight: 300

-zは指定した高さ・幅にそのまま合わせるため、元画像の縦横比とサイズ比が異なると画像が引き伸ばされたり縮んだりする。縦横比を保ちたい場合は後述の-Z--resampleWidthを使う。

-Zで長辺を基準にリサイズする

-Z <ピクセル数>は、縦横比を保ったまま長辺(横長画像なら幅、縦長画像なら高さ)を指定サイズに合わせる。

$ sips -g pixelWidth -g pixelHeight photo.png
/path/to/photo.png
  pixelWidth: 1200
  pixelHeight: 630

$ sips -Z 500 photo.png --out resized.png
$ sips -g pixelWidth -g pixelHeight resized.png
/path/to/resized.png
  pixelWidth: 500
  pixelHeight: 262

元画像は1200x630(横長)なので、長辺の幅が500になり、高さは縦横比を保ったまま262に縮小される。

–resampleWidth/–resampleHeightで幅・高さの片方だけ指定する

--resampleWidth <ピクセル数>または--resampleHeight <ピクセル数>を使うと、幅・高さのどちらか一方だけを指定し、もう一方は縦横比を保って自動計算される。

$ sips --resampleWidth 800 photo.png --out resized_w.png
$ sips -g pixelWidth -g pixelHeight resized_w.png
/path/to/resized_w.png
  pixelWidth: 800
  pixelHeight: 420

$ sips --resampleHeight 300 photo.png --out resized_h.png
$ sips -g pixelWidth -g pixelHeight resized_h.png
/path/to/resized_h.png
  pixelWidth: 571
  pixelHeight: 300

-Zは長辺を基準にするのに対し、--resampleWidth/--resampleHeightは幅・高さを明示的に指定できる。横長画像の高さを基準に縮小したい場合など、-Zでは対応できないケースで使う。

使い分け

オプション用途縦横比
-z <高さ> <幅>高さ・幅を厳密に指定する保たれない
-Z <ピクセル数>長辺を指定サイズに収める保たれる
--resampleWidth <ピクセル数>幅を指定サイズに合わせる保たれる
--resampleHeight <ピクセル数>高さを指定サイズに合わせる保たれる

参考

SIPS Command: Scriptable Image Processing System in macOS