今回はsipsコマンドで画像を印刷した写真風に加工します。今回も処理する画像データなとはデスクトップのsampleフォルダです。cd ~/Desktop/sampleとしてカレントディレクトリを移動しておきましょう。もちろん、GUIを使用しない、できない環境や他のディレクトリがよい場合には、状況に応じて処理する画像ファイルがあるディレクトリに移動しておきましょう。
 なお、今回も元画像データは残しておき、コピーしたものをsampleディレクトリに入れてください。特に今回は元画像を書き換える事が多いため失敗すると元に戻せません。また、一度処理が終わったら再度元画像をsampleディレクトリにコピーしてから、掲載しているコマンドやシェルを実行してください。前回も書きましたが本文中にある-oオプションはsipsのバージョンによっては機能しないことがあります。その場合は-oの代わりに--outを指定してください。

manでマニュアル表示

 まずは画像に余白を付けてみます。余白を付けるとプリンタで印刷した感じになります。さすがにsipsでは絹目調にするような手軽なコマンドはありません。が、sip —helpまたは、manコマンドでman sipsとして表示される説明を見るとJavaScriptで画像の加工ができるとあります。これに関してはsipsコマンドの最後で説明したいと思っています。

そう言えばmanコマンドの説明をしていませんでした。1990年後半からWebが普及したおかげで検索すればコマンドの使い方、応用例などがすぐに出てきます。
それ以前はコマンドの説明(リファレンス)はmanを使うことが多くありました(他は-hや-helpなどのオプションを付けるとコマンド等の説明が表示されたりしました)。manはご想像の通りmanualの単語の略です。

使い方ですがmanと入力し半角空白で区切って調べたいコマンド名を入力します。例えばlsコマンドなら以下のようになります。

長い説明分の場合はカーソルキーの上下で内容をスクロールして見る事ができます。また、スペースキーを押すと次のページに移動します。fキーでも同様です。前のページに戻るにはbキーを押します。qキーを押すとmanが終了し元の画面に戻ります。

Webで検索すればたいがいの事は出てきますが、manで調べるとWebにはない詳しい事も書かれている場合もあります。sipsもmanで確認するとWebで検索しただけでは出てこない情報が表示されます。また、sipsはOSのバージョンによって機能が追加されていたりします。実際に異なるOSのバージョンでman sipsとすると以下のようになります。

  • 向かって左BigSur、右がSnowLeopard

ちなみにどこが変わったのか分からない、という場合は内容をファイルに書き出して比較します。以下のようにするとカレントディレクトリ(現在のディレクトリ)にf1.txtが生成されます。なお、man sipsの出力を保存するとうまくいかないのでsips --helpの結果を保存します。

sips --help > ./f1.txt

わかりやすくデスクトップに生成するなら以下のようになります。

sips --help > ~/Desktop/f1.txt

sipsのバージョンは(10.6.8〜11.3)では3種類のようです。使うなら新しい方がよいでしょう。新しい機能も追加されています。一応手持ちのマシンで出力したman sipsの一覧を示しておきます。

■BigSurの場合

sips - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

  Usages:
    sips [image-functions] imagefile ... 
    sips [profile-functions] profile ... 

  Profile query functions: 
    -g, --getProperty key 
    -X, --extractTag tag tagFile 
        --verify 
    -1, --oneLine 

  Image query functions: 
    -g, --getProperty key 
    -x, --extractProfile profile 
    -1, --oneLine 

  Profile modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
        --deleteTag tag 
        --copyTag srcTag dstTag 
        --loadTag tag tagFile 
        --repair 
    -o, --out file-or-directory 

  Image modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
    -e, --embedProfile profile 
    -E, --embedProfileIfNone profile 
    -m, --matchTo profile 
    -M, --matchToWithIntent profile intent 
        --deleteColorManagementProperties 
    -r, --rotate degreesCW 
    -f, --flip horizontal|vertical 
    -c, --cropToHeightWidth pixelsH pixelsW 
        --cropOffset offsetY offsetH 
    -p, --padToHeightWidth pixelsH pixelsW 
        --padColor hexcolor 
    -z, --resampleHeightWidth pixelsH pixelsW 
        --resampleWidth pixelsW 
        --resampleHeight pixelsH 
    -Z, --resampleHeightWidthMax pixelsWH 
    -i, --addIcon 
        --optimizeColorForSharing 
    -o, --out file-or-directory 
    -j, --js file 

  Other functions: 
        --debug           Enable debugging output
    -h, --help            Show help
    -H, --helpProperties  Show help for properties
        --man             Generate man pages
    -v, --version         Show the version
        --formats         Show the read/write formats

■catalinaの場合

sips - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

  Usages:
    sips [image-functions] imagefile ... 
    sips [profile-functions] profile ... 

  Profile query functions: 
    -g, --getProperty key 
    -X, --extractTag tag tagFile 
        --verify 
    -1, --oneLine 

  Image query functions: 
    -g, --getProperty key 
    -x, --extractProfile profile 
    -1, --oneLine 

  Profile modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
        --deleteTag tag 
        --copyTag srcTag dstTag 
        --loadTag tag tagFile 
        --repair 
    -o, --out file-or-directory 

  Image modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
    -e, --embedProfile profile 
    -E, --embedProfileIfNone profile 
    -m, --matchTo profile 
    -M, --matchToWithIntent profile intent 
        --deleteColorManagementProperties 
    -r, --rotate degreesCW 
    -f, --flip horizontal|vertical 
    -c, --cropToHeightWidth pixelsH pixelsW 
        --cropOffset offsetY offsetH 
    -p, --padToHeightWidth pixelsH pixelsW 
        --padColor hexcolor 
    -z, --resampleHeightWidth pixelsH pixelsW 
        --resampleWidth pixelsW 
        --resampleHeight pixelsH 
    -Z, --resampleHeightWidthMax pixelsWH 
    -i, --addIcon 
        --optimizeColorForSharing 
    -o, --out file-or-directory 
    -j, --js file 

  Other functions: 
        --debug           Enable debugging output
    -h, --help            Show help
    -H, --helpProperties  Show help for properties
        --man             Generate man pages
    -v, --version         Show the version
        --formats         Show the read/write formats

■HighSierraの場合

sips 10.4.4 - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

  Usages:
    sips [-h, --help] 
    sips [-H, --helpProperties] 

    sips [image-query-functions] imagefile ... 

    sips [profile-query-functions] profile ... 

    sips [image modification functions] imagefile ... 
         [--out result-file-or-dir] 

    sips [profile modification functions] profile ... 
         [--out result-file-or-dir] 


  Profile query functions: 
    -g, --getProperty key 
    -X, --extractTag tag tagFile 
    -v, --verify 

  Image query functions: 
    -g, --getProperty key 
    -x, --extractProfile profile 

  Profile modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
        --deleteTag tag 
        --copyTag srcTag dstTag 
        --loadTag tag tagFile 
        --repair 

  Image modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
    -e, --embedProfile profile 
    -E, --embedProfileIfNone profile 
    -m, --matchTo profile 
    -M, --matchToWithIntent profile intent 
        --deleteColorManagementProperties 
    -r, --rotate degreesCW 
    -f, --flip horizontal|vertical 
    -c, --cropToHeightWidth pixelsH pixelsW 
    -p, --padToHeightWidth pixelsH pixelsW 
        --padColor hexcolor 
    -z, --resampleHeightWidth pixelsH pixelsW 
        --resampleWidth pixelsW 
        --resampleHeight pixelsH 
    -Z, --resampleHeightWidthMax pixelsWH 
    -i, --addIcon 
    -o, --optimizeColorForSharing 

■SnowLeopardとMountainLionの場合

sips 10.4.4 - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

  Usages:
    sips [-h, --help] 
    sips [-H, --helpProperties] 

    sips [image-query-functions] imagefile ... 

    sips [profile-query-functions] profile ... 

    sips [image modification functions] imagefile ... 
         [--out result-file-or-dir] 

    sips [profile modification functions] profile ... 
         [--out result-file-or-dir] 


  Profile query functions: 
    -g, --getProperty key 
    -X, --extractTag tag tagFile 
    -v, --verify 

  Image query functions: 
    -g, --getProperty key 
    -x, --extractProfile profile 

  Profile modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
        --deleteTag tag 
        --copyTag srcTag dstTag 
        --loadTag tag tagFile 
        --repair 

  Image modification functions: 
    -s, --setProperty key value 
    -d, --deleteProperty key 
    -e, --embedProfile profile 
    -E, --embedProfileIfNone profile 
    -m, --matchTo profile 
    -M, --matchToWithIntent profile intent 
        --deleteColorManagementProperties 
    -r, --rotate degreesCW 
    -f, --flip horizontal|vertical 
    -c, --cropToHeightWidth pixelsH pixelsW 
    -p, --padToHeightWidth pixelsH pixelsW 
        --padColor hexcolor 
    -z, --resampleHeightWidth pixelsH pixelsW 
        --resampleWidth pixelsW 
        --resampleHeight pixelsH 
    -Z, --resampleHeightWidthMax pixelsWH 
    -i, --addIcon