繁体   English   中英

调整大小和旋转图像-Codeigniter

[英]Resize and rotate image - Codeigniter

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

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

这是代码,希望有人有解决方案:-)

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

$this->image_lib->clear();

加:

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

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

$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中不起作用。

确保在重新发送$ 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'; //

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM