[Front-End General] ImageOptim-CLI で画像ファイルを最適化する

ImageOptim, ImageAlpha, JPEGmini をコマンドラインから利用する。

インストール

% npm install -g imageoptim-cli
% imageOptim -h
Usage: imageOptim [options]
Options:
  -d, --directory     directory of images to process
  -a, --image-alpha   pre-process PNGs with ImageAlpha.app *
  -j, --jpeg-mini     pre-process JPGs with JPEGmini.app **
  -q, --quit          quit all apps when complete
  -h, --help          display this usage information
  -e, --examples      display some example commands and uses
  -v, --version       display the version number
*  http://pngmini.com
** https://itunes.apple.com/us/app/jpegmini/id498944723

つかいかた

下記の Small size の .png ファイルで試してみる。

pitr_Rocket_icon.svg.thumb

% imageOptim -a -q -d ./img
Running ImageAlpha...
find: /var/folders/hj/908kn5w57x3152grk2mt2rrh0000gn/T//imageoptim-cli/png: No such file or directory
Running ImageOptim...
./img/pitr_Rocket_icon.svg.thumb.png was: 4.406kb now: 3.553kb saving: .853kb (19.00%)
TOTAL was: 4.406kb now: 3.553kb saving: .853kb (19.00%)

4.406kb → 3.553kb 19%削減しました。
最初のエラーは、ImageAlpha が指定しているパスが間違ってるバグなのかな?

Version 1.7.10 で、修正対応してくれるそうです。

Version 1.7.10(2013/12/12 03:05)

速攻で対応頂いたみたいで試してみました。

% imageOptim -a -q -d ./img
Running ImageAlpha...
Running ImageOptim...
./img/pitr_Rocket_icon.svg.thumb.png was: 4.406kb now: 2.924kb saving: 1.482kb (33.00%)
TOTAL was: 4.406kb now: 2.924kb saving: 1.482kb (33.00%)

2924 byte でした。さらに最適化されましたね。

grunt-contrib-imagemin

grunt-contrib-imagemin で最適化した結果は、2974 byte でした。

Grunt

ImageOptim, ImageAlpha and JPEGmini for Mac. を grunt から動かします。

補遺

Adobe Unit Types.osax

古い Adobe 製品を利用していると、下記のエラーがでるよう。

上記の「Adobe Unit Types.osax」というファイルを入れ替えると解決した。

% imageOptim -a -q -d ./img
2013-12-11 23:25:21.695 osascript[71137:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
2013-12-11 23:25:22.046 osascript[71187:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
2013-12-11 23:25:22.191 osascript[71191:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
2013-12-11 23:25:22.335 osascript[71195:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
2013-12-11 23:25:22.481 osascript[71199:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
2013-12-11 23:25:22.635 osascript[71204:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
Running ImageAlpha...
find: /var/folders/hj/908kn5w57x3152grk2mt2rrh0000gn/T//imageoptim-cli/png: No such file or directory
Running ImageOptim...
./img/pitr_Rocket_icon.svg.thumb.png was: 4.406kb now: 3.553kb saving: .853kb (19.00%)
TOTAL was: 4.406kb now: 3.553kb saving: .853kb (19.00%)