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