動かざることバグの如し

近づきたいよ 君の理想に

PHPで文字つきの画像を出力する

<?php
$width = 800;
$height = 600;
$font = "./ipag.ttf";
$fontSize = 48;
$text = mb_convert_encoding('エビフライ', 'UTF-8', 'auto');
$img = imagecreate( $width, $height );

$black = ImageColorAllocate( $img, 0x00, 0x00, 0x00 );
$white = ImageColorAllocate( $img, 0xff, 0xff, 0xff );

ImageFilledRectangle( $img, 0, 0, $width, $height, $white );

$box = imagettfbbox($fontSize, 0, $font, $text);
$x = ($width - ($box[2] - $box[0])) / 2;
$y = ($height -($box[5] - $box[3])) / 2;
imageTTFText($img, $fontSize, 0, $x, $y, $black, $font, $text);

header('Content-Type: image/jpeg');
imagejpeg( $img );
imagedestroy( $img );
?>