我使用Codeigniter的图像处理库将上传的图像重新调整为三种尺寸,小尺寸,普通尺寸和大尺寸。Codeigniter图像处理类在调整大小期间旋转图像
重新调整工作效果很好。但是,如果我正在调整垂直图像的大小,则图库会旋转图像以保持水平。
这些都是配置设置我在的地方:
$this->resize_config['image_library'] = 'gd2';
$this->resize_config['source_image'] = $this->file_data['full_path'];
$this->resize_config['maintain_ratio'] = TRUE;
// These change based on the type (small, normal, large)
$this->resize_config['new_image'] = './uploads/large/'.$this->new_file_name.'.jpg';
$this->resize_config['width'] = 432;
$this->resize_config['height'] = 288;
我没有设置master_dim属性,因为默认情况下它设置为auto,这是我想要的。
我的假设是,该库将采取垂直图像,看到高度大于宽度等的图像保持垂直平移适当的高度/宽度配置。
正在发生的事情(显然)是该库旋转图像时,它是垂直的,每个配置上浆它。
这是地方的代码我必须做的实际调整大小:
log_message('debug', 'attempting '.$size.' photo resize');
$this->CI->load->library('image_lib');
$this->CI->image_lib->initialize($this->resize_config);
if ($this->CI->image_lib->resize())
{
$return_value = TRUE;
log_message('debug', $size.' photo resize successful');
}
else
{
$this->errors[] = $this->CI->image_lib->display_errors();
log_message('debug', $size.' photo resize failed');
}
$this->CI->image_lib->clear();
return $return_value;
编辑
我想问题可能是从上传库。当我从上传中得到image_height和image_width时,即使我上传了一个垂直图像,宽度似乎更大。
这是我使用的是上传照片的一部分代码:
$this->upload_config['allowed_types'] = 'jpg|jpeg';
$this->upload_config['max_size'] = '2000';
$this->upload_config['max_width'] = '0';
$this->upload_config['max_height'] = '0';
$this->upload_config['upload_path'] = './uploads/working/';
$this->CI->load->library('upload', $this->upload_config);
if ($this->CI->upload->do_upload($this->posted_file))
{
$this->file_data = $this->CI->upload->data();
$return_value = TRUE;
log_message('debug', 'upload successful');
}
我加了一些记录,检查值:
$this->is_vertical = $this->file_data['image_height'] > $this->file_data['image_width'];
log_message('debug', 'image height:'.$this->file_data['image_height']);
log_message('debug', 'image width:'.$this->file_data['image_width']);
if ($this->is_vertical)
{
$this->resize_config['master_dim'] = 'height';
}
else
{
$this->resize_config['master_dim'] = 'width';
}
log_message('debug', 'master_dim setting:'.$this->resize_config['master_dim']);
这些日志的结果:
DEBUG - 2010-03-16 18:35:06 - > image height:1536 DEBUG - 2010-03-16 18:35:06 - > image width:2048 DEBUG - 2010-03 -16 18:35:06 - > master_dim设置:宽度
看着在Photoshop中的形象,这些都是尺寸:
高度:2048 宽度:1536
任何人都知道可能会导致上传库做到这一点?我从来没有使用这个库,但已经阅读文档
很高兴你已经完成了。好好研究一下下一点! – musoNic80 2010-03-18 09:03:19
你有没有想过一个好方法来保护最终用户不要做同样的事情?我遇到了完全相同的问题。图片看起来正面朝上,但是当您在Safari浏览器中打开它时,它是横向的。 – Catfish 2011-12-23 18:42:43
我从来没有找到一个很好的方法来做到这一点,但说实话,我没有花太多时间去做。 – someoneinomaha 2011-12-30 19:38:34