Codeigniter调整大小和裁剪图像

时间:2015-01-13 11:46:11

标签: codeigniter image-resizing resize-crop imagelibrary

我需要调整图片大小以适应64x64缩略图。我在做什么?我将调整宽度和高度设置为64px。如果我设置$ config ['maintain_ratio'] = false,图像会丢失比例。我做了什么:我设置$ config ['maintain_ratio'] = TRUE;和$ config ['master_dim'] ='宽度';现在宽度总是64px,但高度更大。我以某种方式将图像高度从底部裁剪为64px。我怎样才能做到这一点?我试图设置裁剪功能,但我失败了。也许有另一种解决方案...... 我的调整大小功能

private function resize($up_data) {
        $config['image_library']  = 'gd2';
        $config['source_image']   = $up_data['full_path'];   
        $config['new_image']      = './images/autoriaithumb/';
        $config['create_thumb']   = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['thumb_marker'] = '_thumb';
        $config['width']          = 64;
        $config['height']         = 64;
        $config['quality']        = 100;
        $config['master_dim'] = 'width';

        $this->image_lib->initialize($config);

        $this->image_lib->resize();

}

1 个答案:

答案 0 :(得分:0)

试试这个

将'upload config'定义为$ image_config并定义你的裁剪配置....作为$ config

$this->load->library('upload', $image_config);
if ($this->upload->do_upload()) {
  $this->load->library('image_lib',$config); 
  $this->image_lib->resize();
}