关于php:调整大小并旋转图像-Codeigniter

Resize and rotate image - Codeigniter

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$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();

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

1
2
3
4
5
6
7
$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中不起作用。


之后

$this->image_lib->clear();

添加:

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


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

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

此刻rotate()得到一个$ config,如下所示:

1
2
3
4
5
6
7
8
$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'; //