我寫此代碼:圖象信息生成問題形成一類
class Generate{
private $canvas;
function __construct($width, $height){
$this->canvas = imagecreatetruecolor($width, $height);
}
public function bg($r=0,$g=0,$b=0){
$color = imagecolorallocate($this->canvas, $r, $g, $b);
imagefill($this->canvas, 0, 0, $color);
}
public function gen(){
header('Content-Type: image/png');
imagepng($this->canvas, NULL, 9);
imagedestroy($this->canvas);
}
}
以及與此稱之爲:
$G = new Generate(100, 100);
$G->bg(255, 255, 255);
$G->gen();
其生成圖像細當我在根註釋掉報頭( )功能並將其設置爲保存圖像。像這樣:
imagepng($this->canvas, 'img.png', 9);
但我希望它發送標題(輸出圖像),但它給了我一個錯誤。有人能告訴我我做錯了什麼嗎?你甚至可以在PHP類中發送頭文件?當我不使用OOP
所以你想保存圖像,並輸出它? – sberry
你沒有告訴我們當你不發表評論時發生了什麼。 –
@ sberry2A不只是輸出... – Ameer