CodeIgniter图像仅在动态输出上裁剪

时间:2011-10-11 15:44:02

标签: php codeigniter image-resizing

我正在尝试使用内置的图像处理类在CodeIgniter中裁剪图像。下面的代码工作正常,您将调整大小的图像输出到浏览器。但是,当您删除“$config['dynamic_output'] = TRUE;”行时,它不再裁剪图像,而只是保存原始图像。我做错了什么?!

非常感谢任何帮助,谢谢!

public function crop() {        
    $config['library_path'] = '/usr/local/bin';
    $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/static/images/moose_resized.jpg';
    $config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/static/images/moose_thumb.jpg';
    $config['x_axis'] = '0';
    $config['y_axis'] = '74';
    $config['width'] = '222';
    $config['height'] = '111';
    $config['maintain_ratio'] = FALSE;
    $config['quality'] = '100';
    $config['dynamic_output'] = TRUE;

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

    $this->image_lib->crop();

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

    $this->load->view('crop');

}

1 个答案:

答案 0 :(得分:1)

好的,所以没有人得到任何积分,因为他们没有发现上面代码中的愚蠢错误!

$this->image_lib->crop();

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

在临时精神错乱的时刻,我添加了裁剪线,而不是在if语句中替换resize。咄!