我在“image_lib”库加载后使用了这段代码。 ini_set(-6ren">
gpt4 book ai didi

php - 代码点火器中的 "gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file"

转载 作者:可可西里 更新时间:2023-11-01 12:53:28 26 4
gpt4 key购买 nike

我正在使用 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 >>

我在“image_lib”库加载后使用了这段代码。

ini_set('gd.jpeg_ignore_warning', 1);

有什么办法吗?提前致谢!

最佳答案

问题是 error suppression未打开函数 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;
}

}

关于php - 代码点火器中的 "gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14735666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com