1

我正在尝试调整图像大小和旋转图像。

目前它只是调整图像大小,而不是旋转它。

这是代码,希望有人有解决方案或其他东西:-)

$config['image_library']   = 'gd2';
$config['source_image']    = $data['full_path'];
$config['new_image']       = $data['file_path'].'thumbs/'.$data['file_name'];
$config['create_thumb']    = FALSE;
$config['maintain_ratio']  = TRUE;
$config['width']           = 235;
$config['height']          = 235;

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

$this->image_lib->resize();

$this->image_lib->clear();

$config['create_thumb'] = FALSE; //No thumbnail
$config['source_image'] = $data['file_path'].'thumbs/'.$data['file_name']; //full path for the source image
$config['rotation_angle'] = '180';// 

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

//Rotate the image
$this->image_lib->rotate();
4

3 回答 3

3

清除配置后,不要重新加载库,重新初始化:

$this->image_lib->clear();
$config=array();
$config['image_library']   = 'gd2';
$config['source_image'] = $data['file_path'].'thumbs/'.$data['file_name'];
$config['rotation_angle'] = '180';
$this->image_lib->initialize($config); // reinitialize it instead of reloading
$this->image_lib->rotate();

这是最终对我有用的唯一解决方案。只是重新初始化 $config 在 CodeIgniter 2.2.0 中不起作用。

于 2014-12-17T19:10:46.777 回答
3

$this->image_lib->clear();

添加:

$config = array()重新初始化您的配置数组。

于 2012-04-26T17:07:20.390 回答
0

确保在再次发送之前重新创建 $config。

否则,您最终可能会发送您不想发送的值。

目前 rotate() 得到一个像这样的 $config :

$config['image_library']   = 'gd2';
$config['new_image']       = $data['file_path'].'thumbs/'.$data['file_name'];
$config['maintain_ratio']  = TRUE;
$config['width']           = 235;
$config['height']          = 235;
$config['create_thumb'] = FALSE; //No thumbnail
$config['source_image'] = $data['file_path'].'thumbs/'.$data['file_name']; //full path for the source image
$config['rotation_angle'] = '180'; //
于 2012-04-26T13:56:02.540 回答