GD 库显示特殊字符

时间:2021-02-11 21:06:25

标签: php laravel gd

如你所见,我已经安装了 GD 库。(图片) 但是当我尝试创建图像时,它显示特殊字符而不是图像。(图像) 我正在使用 laravel 和 Xampp。

有人知道是什么问题吗?

<?php
  

// create a blank image
$image = imagecreatetruecolor(400, 300);

// fill the background color
$bg = imagecolorallocate($image, 0, 0, 0);

// choose a color for the ellipse
$col_ellipse = imagecolorallocate($image, 255, 255, 255);

// draw the white ellipse
imagefilledellipse($image, 200, 150, 300, 200, $col_ellipse);

// output the picture
header("Content-type: image/png");
imagepng($image); ?>

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您希望图像显示为图像,则需要在发送 Order By [SomeField] 之前删除任何输出。从您的代码中删除 header 以查看实际图像:

var_dump(gd_info());

来自https://www.php.net/manual/en/function.header.php

"记住必须在发送任何实际输出之前调用 header()"