2011-10-27 20 views
0

當我在網頁中調用我的圖像大小調整功能,它運行平穩,調整圖片的大小,但是當我包括在我的索引頁,並從的index.php然後頭不叫發送併產生如此長的文字圖像頭不會從OOP傳遞到index.php

=>GIF87aªç–ƒx‡dWtaZffeCA<ÕƶCBBŠVNfXT;BC§‡w²¤™wxw¹†g‡˜–êÆ©C;:x‡‡ˆˆ… 

等等。請解決我的問題,否則我會直接在index.php中創建這個函數?

下面

class img{ 
function resize() 

{ 

// File and new size 
$filename = 'upload/845.gif'; 
$percent = 0.5; 

// Content type 
ob_start(); 

echo header("Content-Type: image/gif"); 

ob_end_clean(); 


// Get new sizes 
list($width, $height) = getimagesize($filename); 
$newwidth = $width * $percent; 
$newheight = $height * $percent; 

// Load 
$thumb = imagecreatetruecolor($newwidth, $newheight); 
$source = imagecreatefromgif($filename); 

// Resize 
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

// Output 
@imagegif($thumb); 
imagedestroy($thumb); 
} 
} 

這是我function.php網頁代碼這是我的index.php代碼如下

<html> 
<body> 
<?php 
include("function.php"); 
$img_resize=new img; 
$img_resize->resize(); 
?> 
</body> 
</html> 
+0

這是什麼都與OOP呢? –

+0

它生成縮略圖.... – waqaxi

+0

是否有其他內容您打算在同一時間顯示,或者你只是想顯示圖像? – ray

回答

2

您需要創建一個單獨的文件,以輸出的圖像,然後在<img>標籤加載它。

// image.php 
include("function.php"); 
$img_resize=new img; 
$img_resize->resize(); 

// HTML file 
<html> 
    <body> 
    <img src="image.php" /> 
    </body> 
</html> 

這就是如果您試圖將圖像包含在HTML文件中。如果您只是試圖輸出圖像,正如其他人暗示的那樣,那麼您根本不需要任何HTML就可以輸出圖像。

+0

:-)是的其工作的傢伙.....歡呼聲.... :-) – waqaxi

+0

但如何將我送我從數據庫中while循環 – waqaxi

+0

嘗試得到了這個形象的名字使用' Clive

2

您發送的頭信息,你所輸入的body標記之後。

我建議完全移除HTML如果你所顯示的圖像。

+0

+1:但不應該有任何HTML ** **! –

+0

問題依然存在...... – waqaxi

-1
ob_start(); 
echo header("Content-Type: image/gif"); 
ob_end_clean(); 

嘗試就這樣

header("Content-Type: image/gif"); 
+0

沒錯! ...但它向我發送了「header already sent」錯誤,沒有ob_start – waqaxi