我已经建立了一个图片库和保存图像“原样”无需裁剪它。我想在加载到控制器中的同时实时调整图像大小,因此当我在浏览器中加载控制器时,它会根据我的需要显示图像的大小。我已将该方法添加到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