开发者

Image lib - can`t reduce the quality of a image

Im trying to reduce the quality of uploaded image. Here is my code

$image_config['source_ima开发者_JS百科ge'] = 'file.jpg';
$image_config['maintain_ratio'] = TRUE;
$image_config['quality']    = '30%';
$image_config['width'] = 1680;
$image_config['height'] = 1050;

$this->load->library('image_lib', $image_config);
$this->image_lib->resize();

The problem is so image has the same quality as the file.jpg etc it is not reduced.


I face same problem and I found something in image library file.

system/libraries/image_library.php line 455

if ($this->dynamic_output === FALSE)
    {
        if ($this->orig_width == $this->width AND $this->orig_height == $this->height)
        {
            if ($this->source_image != $this->new_image)
            {
                if (@copy($this->full_src_path, $this->full_dst_path))
                {
                    @chmod($this->full_dst_path, FILE_WRITE_MODE);
                }
            }

            return TRUE;
        }
    } 

This code ignore image rendering if width and height of destination image is the same as the source image. Remove the above code and it should works.


Hey Nick, have you tried to display the errors?

if ( ! $this->image_lib->resize())
{
    echo $this->image_lib->display_errors();
}

Possible errors I can think of : not giving the correct path to the file or not having installed one of the 3 image libraries (GD/GD2, NetPBM or ImageMagick)

Hope this helps!


You just need need to give Numeric value not with "%" sign

Like $image_config['quality'] = '30';


Also check the real mime type. PNG files renamed with JPG extension cannot be reduced by quality.

$info = getimagesize($_filepath);
echo $info['mime'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜