“gd-jpeg,libjpeg:recoverable error:Earlyature of JPEG file”在Codeigniter [英] "gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file" in Codeigniter

查看:434
本文介绍了“gd-jpeg,libjpeg:recoverable error:Earlyature of JPEG file”在Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用codeigniter并尝试创建图像的缩略图。我成功了。但对于一些图像我不成功。我收到此错误。

I am using codeigniter and trying to create thumb of images. i was successful. but for some images i am not successful. i am getting this error.

<< 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'库加载后使用此代码。

i used this code after 'image_lib' library load.

ini_set('gd.jpeg_ignore_warning', 1);

之后,一些图像拇指创建成功...但还是没有解决方案。任何解决方案?

after that some images thumb creation was successful...but still no solution for some others.... any solution?

推荐答案

问题是 imagecreatefromjpeg

最好的选择是扩展基本库并重载 image_create_gd 方法

The best option is to extend the base library and overload the image_create_gd method

创建一个新文件 ./ 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;
}

}

这篇关于“gd-jpeg,libjpeg:recoverable error:Earlyature of JPEG file”在Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆