2008/06/04
php:フォントのダイナミックな画像キャッシュ
かぶせてエントリー。キャプション用テキスト画像を動的に生成
こういうの→
![]()
<?
//画像キャッシュ
gif_text('as3:フォントのダイナミックなローディング');
function gif_text($text){
$f = md5($text).'.gif';
if(!file_exists($f)){
if(mb_strlen($text)==strlen($text)){
$size = 18;
$font = 'helvetica.ttf';
}else{
$size = 16;
$font = 'KozGoPro-Medium.otf';
}
$box = imagettfbbox ( $size, 0, $font, $text );
$width = $box[2]-$box[6]+3;
$height = $box[3]-$box[7];
$img = imagecreatetruecolor( $width, $height);
$bg = imagecolorallocate($img, 255, 255, 255);
$color = imagecolorallocate($img, 96, 96, 96);
imagefilledrectangle($img, 0, 0, $width, $height, $bg);
imagettftext($img, $size,0, -$box[6], -$box[7], $color, $font, $text);
imagegif($img,$f);
imagedestroy($img);
}
?><img src="<?=$f?>" /><?
}
?>
コメント一覧