Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

アニメーションGIFでCAPTCHA

This package can be used to perform human user validation using CAPTCHA images (Completely Automated Public Turing to tell Computers from Humans Apart).

It generates a sequence of animated images, assembled with in a GIF animation file, to make it more difficult to break by robots because the validation text does not completely appear in each of the animation images.

The text length, color and font are configurable.

先日エントリしたアニメGIFを作るパッケージをメンテしているLászló Zsidi氏が作ってます。目の付け所が良いですね :-)

またもやダウンロードして試してみました。なお、先日エントリしたアニメGIFを作るパッケージが必要になります。
任意のディレクトリに展開後、captchaディレクトリの権限を変更します。ここにCAPTCHAに表示される文字列を格納したファイルが生成されます。

$ chmod 777 captcha/

次に、captcha.phpの49行目にある

$captcha = new Captcha ( ..., "fonts/verdana.ttf", ... );

のフォント名を適当に変更します。今回は

$captcha = new Captcha ( ..., "/usr/share/fonts/ja/TrueType/kochi-gothic-subst.ttf", ... );

としました。
また、変数の初期化絡みでNoticeが出まくります :-( ので、php.iniのdisplay_errorsをoffにしてApacheを再起動、もしくは、.htaccess

php_flag display_errors off

としておきます。
終わったら、ブラウザからindex.phpにアクセスしてみましょう。[Another CAPTCHA projectScreenshotにあるようなアニメーションGIFが表示されているはずです。

アニメーションGIFが動的作成できると、その応用範囲は意外と広いかも知れませんね。