1
我有问题。 此代码应该生成文本到图像并在页面上显示,但这不起作用。这显示丢失的图像图标。代码:图像丢失而不是imagepng
$stmt = $pdo->prepare("SELECT * FROM imiona");
$stmt -> execute();
while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
$id = $row['id'];
$japan = $row['imie_japan'];
$polish = $row['imie_polish'];
echo "<b>".$polish."</b><br>";
echo $japan."<br>";
header("Content-type: image/png");
$fontsize = 40;
$fonttype = 'ARIAL.TTF';
$width = imagefontwidth($fontsize) * strlen($japan);
$height = imagefontheight($fontsize);
$image = imagecreatetruecolor($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);
imagettftext($image,$fontsize,0,0,0,$black,$fonttype,$japan);
imagepng ($image);
imagedestroy($image);
echo "<br>"; }
你有一个循环,你在每个循环中发送标题?这不会做到这一点。图像不应该输出任何HTML元素,而不是图像内容。创建一个单独的文件来映射图像。 –