图像库 - 不能降低图像的质量


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

我试图降低上传图像的质量。这是我的代码

$image_config['source_image'] = '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();

问题是图像具有与文件相同的质量.jpg等等,它不会降低。

我遇到了同样的问题,我在图像库文件中发现了一些东西。

系统/库/image_library.php 第 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;
        }
    } 

如果目标图像的宽度和高度与源图像相同,则此代码将忽略图像呈现。删除上面的代码,它应该可以工作。

嘿尼克,你有没有尝试显示错误?

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

我能想到的可能错误:没有提供正确的文件路径或没有安装3个图像库(GD/GD2,NetPBM或ImageMagick)之一

希望这有帮助!

你只需要给出不带"%"符号的数值

喜欢$image_config['quality'] = '30';

还要检查真实的 MIME 类型。使用 JPG 扩展名重命名的 PNG 文件无法按质量降低。

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