Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在网页内显示带有GD库的jpeg图像时出错_Php_Header_Gd - Fatal编程技术网

Php 在网页内显示带有GD库的jpeg图像时出错

Php 在网页内显示带有GD库的jpeg图像时出错,php,header,gd,Php,Header,Gd,我已经创建了一个图像类来显示和转换带有GD库的站点上的图像。当我想在站点中显示没有任何HTML代码的jpeg图像时 一切都会好的,因为我设置了标题('Content-Type:image/jpeg')。 我的代码如下: $filepath = 'path to the image file'; $info = getimagesize( $filepath ); $this->type = $info[2]; if( $this->type == IMAGETYPE_JPEG )

我已经创建了一个图像类来显示和转换带有GD库的站点上的图像。当我想在站点中显示没有任何HTML代码的jpeg图像时 一切都会好的,因为我设置了标题('Content-Type:image/jpeg')。 我的代码如下:

$filepath = 'path to the image file';
$info = getimagesize( $filepath );
$this->type = $info[2];
if( $this->type == IMAGETYPE_JPEG ) 
{
    $this->image = imagecreatefromjpeg($filepath); // set the resource image
} 
   if( $this->type == IMAGETYPE_JPEG )
   {
    $type = 'image/jpeg';
   }
 header('Content-Type: ' . $type );
  if( $this->type == IMAGETYPE_JPEG )
  {
    imagejpeg( $this->image );
   }

这段代码工作得很好,但是如果我想在HTML代码中显示图像(ob_start不起作用),我应该如何显示它们。

像普通图像一样从不同的文件请求脚本:

<img src="path/to/the/file/that/outputs/the/image.php">


非常感谢!我的问题已经解决了,但我有一个新问题,加载只包含一个图像的页面需要很长时间(2-3秒)。我应该如何解决这个问题?有什么解决办法吗?提前谢谢,这是不可能回答的。查看您的浏览器工具(Firebug/Web Inspector/您正在使用的任何其他工具)以了解为什么要花这么长时间加载。