コマンドラインで画像ファイルを操作する方法

画像ファイルに対してサムネイルを簡単に作れないかなと思ってたら、そのものズバリなコマンドがあるみたい。

例えば、foo.jpgって画像から50px×50pxのサムネイル画像を作ろうと思ったら、たったのこれだけ。

$ sips -z 75 75 foo.jpg --out foo_thumb.jpg

thumbディレクトリ以下にサムネイル画像を出力するワンライナーを書くとしたらこんな感じかな。

$ mkdir thumb
$ for file in `ls *.jpg` ; do echo "--- $file"; sips -g all $file; sips -z 75 75 $file --out thumb/$file; done

参考までにヘルプも載せておく。色々なことができるっぽい。

$ sips -h
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