在图片上传成功后,调用图片裁剪功能
1.加载CI类库以及配置文件
$this->load->library('image_lib');
$config_thumb = $this->config->item("image_thumb");
配置文件
//缩略图 $config['image_thumb'] = array( //gd2图库 'image_library' => 'gd2', //是否创建缩略图 'create_thumb' => true, 'maintain_ratio' => true, );
程序中调用
$config_thumb['source_image'] = $this->upload->data('full_path'); $config_thumb['new_image'] = $thumbpath."/".$imgname; $big_thumb = thumbUploadImg($config_thumb,array(300,300,"_300_300",)); $this->image_lib->initialize($big_thumb); $this->image_lib->resize();
自定义图片裁剪封装
/*************** * @function 自定义上传图片裁剪 * @Param: * $thumb : 项目配置中的基本参数,必须有 * $param 自定义配置,可选,一维索引数组 * $config : 默认配置中的基本参数,可以自定义覆盖 * @Return: $thumb; 图片裁剪配置 ***************/ function thumbUploadImg($thumb,$param = array()){ if (count($param) == 3){ $config['width'] = $param[0]; $config['height'] = $param[1]; $config['thumb_marker'] = $param[2]; }else{ $config['width'] = 150; $config['height'] = 150; $config['thumb_marker'] ="_150_150"; } $thumb = array_merge($thumb,$config); return $thumb; }