我想用php脚本显示图像。这是我目前的代码:如何返回图像
<?php
if (isset ($_GET['id'])) $id = $_GET['id'];
$t=getimagesize ($id) or die('Unknown type of image');
switch ($t[2])
{
case 1:
$type='GIF';
$img=imagecreatefromgif($path);
break;
case 2:
$type='JPEG';
$img=imagecreatefromjpeg($path);
break;
case 3:
$type='PNG';
$img=imagecreatefrompng($path);
break;
}
header("Content-type: image/".$type);
echo $img;
?>
但它不显示图像。什么是正确的方式,而不是echo $img
?
' 警告:imagejpeg():提供的参数不是有效的图像资源'到你的代码的第二行 – Ockonal 2011-05-19 12:16:22
该问题询问**返回**图像...恕我直言,这家伙的答案是去:[链接](https://stackoverflow.com/questions/22266402/how-to-encode-an-image-resource-to-base64)...结合这另一个[链接](https:// stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html)必须完成这项工作。 – Nowdeen 2017-07-25 13:16:39