Php 缺少图像而不是imagepng

Php 缺少图像而不是imagepng,php,Php,我有个问题。 该代码应该生成一个图像文本,并在页面上显示,但不起作用。显示丢失的图像图标。代码: $stmt = $pdo->prepare("SELECT * FROM imiona"); $stmt -> execute(); while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) { $id = $row['id']; $japan = $row['imie_japan']; $polis

我有个问题。 该代码应该生成一个图像文本,并在页面上显示,但不起作用。显示丢失的图像图标。代码:

$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>"; }
$stmt=$pdo->prepare(“从imiona中选择*);
$stmt->execute();
而($row=$stmt->fetch(PDO::fetch\U ASSOC)){
$id=$row['id'];
$japan=$row['imie_japan'];
$polish=$row['imie_polish'];
回声“$polish.”
“; 回声$japan.“
”; 标题(“内容类型:图像/png”); $fontsize=40; $fonttype='ARIAL.TTF'; $width=imagefontwidth($fontsize)*斯特伦($japan); $height=imagefontheight($fontsize); $image=imageCreateTureColor($width,$height); $white=imagecolorallocate($Image255255); $black=imagecolorallocate($image,0,0,0); 图像填充($image,0,0,$white); imagettftext($image,$fontsize,0,0,0,$black,$fonttype,$japan); imagepng($image); 图像销毁($图像); 回声“
”;}
您不仅显示了一个图像,还回显了多个字符串,如
“$polish.”
“;
$japan.”
“;
,然后在末尾添加一个

标记


删除所有导致图像本身中断的内容,因为您无法在编码图像前后回显随机字符串。

您不仅显示图像,还回显了多个字符串,如
“$polish”。
$japan.“

标记


删除所有。。。这会导致图像本身中断,因为您无法在编码图像前后回显随机字符串。

您有一个循环,并且在每个循环中发送头?那不行。图像不应输出任何HTML元素,而应输出图像内容。创建一个单独的文件来映射图像。您有一个循环,并且在每个循环中发送头?那不行。图像不应输出任何HTML元素,而应输出图像内容。创建用于映射图像的单独文件。