2012-04-12 43 views
0

我创建了一个图像类以在GD网站上显示和转换网站上的图像。当我想在网站 中显示没有任何HTML代码的jpeg图像时,一切都会好起来,因为我设置了标题('Content-Type:image/jpeg')。 我的代码是象下面这样:使用GD库在网页中显示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没有工作)。

回答

0

请求从不同的文件脚本就像任何普通的图像:

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

本人不胜感激!我的问题已经解决,但我有一个新问题需要花费很多时间(2-3秒)来加载只包含一个图像的页面。我应该如何解决这个问题?有没有解决方案?在此先感谢 – ALH 2012-04-12 08:31:24

+0

这是不可能回答。看看你的浏览器工具(Firebug/Web Inspector /你正在使用的任何其他软件),弄清楚为什么*加载需要很长时间。 – deceze 2012-04-12 08:49:42