我使用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