调整大小并旋转图像 - Codeigniter

时间:2012-04-26 13:52:14

标签: php codeigniter rotation image-resizing

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

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

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

$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();

3 个答案:

答案 0 :(得分:3)

之后

$this->image_lib->clear();

添加:

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

答案 1 :(得分:1)

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

$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中没有用。

答案 2 :(得分: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'; //