画像の変形やコンバートなんかで有名なImageMagickってのがありますが、その機能をphp側で利用するためのインターフェース拡張があります。pearではなくpecl側で用意されているもので「PECL :: Package :: imagick」という物。
これ、非常に便利な機能なんですが、インストに良くハマる。
こないだ再度同じ場所でハマったのでメモしておく、結果を先に行っちゃうとバージョンの問題なので、俺のアホさが際立っているわけですが内緒です。というわけでインストールメモを書いてみる。
とりあえずImageMagickをインストールする。これは、別にyumだのaptだので入れても良いと思います。が、なんとなくソースからインスト。普通に「ImageMagick: Downloads」からダウンロードしてきて、.configure 、makeで完了。
ここからが問題。imagick側がまだ開発段階で1.x系では正しく動かない+インストール出来ない事が多々ある。なので0.9x系を入れないといけない。
pecl bundle imagick-0.9.13 cd imagick phpize ./configure make cp modules/imagick.so /path/to/extension/
こんな感じ。peclから該当のバージョンをダウンロードして自分でコンパイルする形。後はphp.iniのような設定に以下書き込んで終わり。
extension=imagick.so
なんか、何回も失敗すると凹み度が高い。ちなみに、imagick自体の使い方はこちらが詳しいと思う→「Documentation PHP-Imagick」
phpを使ってコマンドラインの軽いスクリプトを組む時に、APCのようなキャッシュや、Browser Capabilities(browscap)とかでブラウザ判別をしてたりすると、コマンドラインを起動するのに色々Warningとかが表示されて面倒な時が多い。
とりあえずそれを別口のini(php.ini)を用意して、コマンドラインでphpを起動する時はその別の設定ファイルを読み込ませる事ができるそうなので、メモ。
例としては以下のような感じになる。要するにAPCだのbrowscapなどのコマンドラインなんかでは使わないようなライブラリは外した別のiniファイルを用意してそれを読み込みましょうという事。
#!/usr/bin/php -c /path/to/phpcli.ini print "hoge"; exit();
一行目のphpの場所を指定する部分にオプション「-c」を付けて設定ファイルを読み込んでいただきましょうという感じ。ちなみに、実行のたびに設定ファイルは読み直されるらしいです(ここではphpcli.ini)。
起動オプションは他にも色々あるらしいので、一応下に自分へのメモも含めてコピペしておきます。
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a
-a Run interactively
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
--ini Show configuration file names
--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
--ri <name> Show configuration for extension <name>.