我已經建立了一個圖片庫和保存圖像「原樣」無需裁剪它。我想在加載到控制器中的同時實時調整圖像大小,因此當我在瀏覽器中加載控制器時,它會根據我的需要顯示圖像的大小。我已將該方法添加到MY_Loader
,這裏是代碼。調整圖像大小和顯示,但不保存
function show_image($image, $width, $height) {
$this->helper('file');
$image_content = read_file($image);
//resize image
$image = imagecreatefromjpeg($image);
$thumbImage = imagecreatetruecolor(50, 50);
imagecopyresized($thumbImage, $image, 0, 0, 0, 0, 50, 50, $width, $height);
imagejpeg($thumbImage,"",85);
imagedestroy($image);
imagedestroy($thumbImage);
header('Content-Length: '.strlen($image_content)); // sends filesize header
header('Content-Type: '. get_mime_by_extension($image)); // send mime-type header
header('Content-Disposition: inline; filename="'.basename($image).'";'); // sends filename header
exit($image_content); // reads and outputs the file onto the output buffer
}
從這段代碼中,我收到很多錯誤,包括標頭錯誤。我究竟做錯了什麼?
錯誤:(如果有用的話)
Message: imagejpeg(): Filename cannot be empty
Message: Cannot modify header information - headers already sent by (output started at /Volumes/www/vhosts/ci/system/core/Exceptions.php:185)
Message: strrchr() expects parameter 1 to be string, resource given
Message: Cannot modify header information - headers already sent by (output started at /Volumes/www/vhosts/ci/system/core/Exceptions.php:185)
Message: basename() expects parameter 1 to be string, resource given
Message: Cannot modify header information - headers already sent by (output started at /Volumes/www/vhosts/ci/system/core/Exceptions.php:185)
您好!你可以在這裏粘貼錯誤信息嗎? 問題可以是previousli發送了頭,等... PHP代碼之前 HTML代碼..等等... – Kovge 2013-03-10 07:30:57
補充一下上面 – 2013-03-10 07:35:50
沒有HTML正在裝載IM剛剛從控制器測試調用它。 – 2013-03-10 07:49:29