我正在使用CodeIgniter并尝试创建大拇指的图像.我成功了一些但在某些情况下失败了.我收到以下错误 -
<< A PHP Error was encountered
Severity: Notice
Message: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
Filename: libraries/Image_lib.php
Line Number: 1155 >>
Run Code Online (Sandbox Code Playgroud)
我在'image_lib'库加载后使用了这段代码.
ini_set('gd.jpeg_ignore_warning', 1);
Run Code Online (Sandbox Code Playgroud)
任何解决方案 提前致谢!
问题是该函数没有开启错误抑制imagecreatefromjpeg
最好的选择是扩展基础库并重载该image_create_gd方法
创建一个新文件./application/libraries/MY_Image_lib.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class MY_Image_lib extends CI_Image_Lib {
function image_create_gd($path = '', $image_type = '')
{
if ($path == '')
$path = $this->full_src_path;
if ($image_type == '')
$image_type = $this->image_type;
switch ($image_type)
{
case 1 :
if ( ! function_exists('imagecreatefromgif'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
return FALSE;
}
return @imagecreatefromgif($path);
break;
case 2 :
if ( ! function_exists('imagecreatefromjpeg'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
return FALSE;
}
return @imagecreatefromjpeg($path);
break;
case 3 :
if ( ! function_exists('imagecreatefrompng'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
return FALSE;
}
return @imagecreatefrompng($path);
break;
}
$this->set_error(array('imglib_unsupported_imagecreate'));
return FALSE;
}
}
Run Code Online (Sandbox Code Playgroud)