透過gif
透過gifはツールを使えば作れるのだけどphpで動的に作れるかと調べたところ、サンプルもあったので自分なりに確認して忘れないようにメモ。
インストール
debian
系のインストール、centos
でも yum
でモジュールは一緒かな?(未確認)
# apt-get -y install php5 php5-gd
サンプル
phpサンプル
php
ドキュメントのサンプルをほぼそのまま。
gif.php
// 新しい画像のインスタンスを作成します
$im = imagecreatetruecolor(100, 100);
// 背景を白にします
$white = imagecolorallocate($im, 255,255,255);
imagefilledrectangle($im, 0,0,99,99, $white);
// テキスト文字列を画像の上に描画します
imagestring($im, 3, 20, 20, 'GD Library', 0xFFBA00);
// 透明色を指定
imagecolortransparent($im, $white);
// 画像をブラウザに出力します
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
htmlサンプル
gif
だけ表示しても透過の具合が分からないので、背景色を付けて呼んでみます。
gif.html
<html>
<head>
</head>
<body>
<table border="1">
<tr style="background-color:#CC0066;">
<td><img src="/gif.php"></td>
</tr>
<tr style="background-color:#CC0066;">
<td>sample</td>
</tr>
</table>
</body>
</html>
実際の表示
同じフォルダに置いて、gif.html
を呼ぶと透過になっていますね。