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沒有工作)。
本人不勝感激!我的問題已經解決,但我有一個新問題需要花費很多時間(2-3秒)來加載只包含一個圖像的頁面。我應該如何解決這個問題?有沒有解決方案?在此先感謝 – ALH 2012-04-12 08:31:24
這是不可能回答。看看你的瀏覽器工具(Firebug/Web Inspector /你正在使用的任何其他軟件),弄清楚爲什麼*加載需要很長時間。 – deceze 2012-04-12 08:49:42