我曾使用gd2库调整图像大小,但某些图像在调整大小后旋转了90度,但不是全部图像。我没有使用任何旋转,这可能是什么原因呢?是否需要设置其他配置?
我的代码在这里:
if(isset($_FILES) && !empty($_FILES)){
$item_images = $_FILES;
$this->load->library('upload');
$this->load->library('image_lib');
$config['upload_path'] = './temp/';
$config['allowed_types'] = '*';
$this->upload->initialize($config);
//print_r($item_images);
foreach($item_images as $ind=>$img_name){
if($this->upload->do_upload($ind)){
$data_image = $this->upload->data();
//for cropping
$config_crop['image_library'] = 'gd2';
$config_crop['source_image'] = $config['upload_path'] . $data_image['file_name'];
$config_crop['create_thumb'] = FALSE;
$config_crop['maintain_ratio'] = TRUE;
$config_crop['width'] = 300;
$config_crop['height'] = 300;
//$config_crop['rotation_angle'] = '0';
//$config_crop['x_axis'] = '100';
//$config_crop['y_axis'] = '40';
$this->image_lib->initialize($config_crop);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
}
$image_thumb = $this->s3_model->upload_image('thumb_'.$img_name['name'] ,$config['upload_path'] . $data_image['file_name']);
if($image_thumb){
$result = $this->s3_model->upload_image($img_name['name'] ,$img_name['tmp_name']);
//unlink($config['upload_path'] . $data_image['file_name']);
}
if(! $result){
$flag = false; //Error in uploading image.
break;
}
}
}
您有OSx工作机吗?
以我为例,在我的Mac中正确显示的图片确实向侧面倾斜,这是因为在拍摄图片时OSX预览检测到了手机的方向...。
服务器不行,Windows机器也不行……这让我发疯了……
无论您是否遇到这种情况,都可以使用exif_read_data()函数。如果照片的元数据中存在取向数据,它将为您提供取向数据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句