忘記我發佈了這個。我想出瞭如何處理定位問題,所以我想我會分享。現在看起來很簡單。我從此使用Codeigniter重新創建了這個項目。 CI很棒,節省了很多時間,但我很高興自己第一次寫下了這些。我當然學到了更多的方法。
首先,如果文件是JPG文件,我會得到帶有PEL的EXIF數據。
$new
是上傳的文件進行檢查的方向。
$this->load->library('pel/PelJpeg');
if($ext == 'jpg'){
$pdw= new PelDataWindow(file_get_contents($new));
if(PelJpeg::isValid($pdw)){
$input_jpg = new PelJpeg($new);
$exif = $input_jpg->getExif();
}
}
那麼如果EXIF存在,請方向值,並通過一個switch語句運行它,因此它旋轉,然後重置姿勢值。我使用的是image_moo和Codeigniter,但是顯然這可以改爲使用任何圖像操作庫。
我真的不確定是否所有那些IF語句都需要在那裏,但是我一直遇到了只包含一些EXIF信息的jpg問題,並且會在沒有它們的情況下炸燬腳本。
if($exif !== NULL){
if($tiff = $exif->getTiff()){
if($ifd0 = $tiff->getIfd()){
if($orient = $ifd0->getEntry(PelTag::ORIENTATION)){
$this->image_moo->load($new);
//find the orientation value from the orientation tag. May be a better way, but this works for me.
$orientation = str_replace(' ', '', $orient);
//The orientation value from the orientation tag is after 'Value:'
if (($tmp = strstr($orientation, 'Value:')) !== false) {
$str = substr($tmp, 6, 1);
}
switch ($str)
{
// up is pointing to the right
case 8:
$this->image_moo->rotate(90);
$orient->setValue(1);
break;
// image is upside-down
case 3:
$this->image_moo->rotate(180);
$orient->setValue(1);
break;
// up is pointing to the left
case 6:
$this->image_moo->rotate(270);
$orient->setValue(1);
break;
// correct orientation
case 1:
break;
}
$this->image_moo->save($new,TRUE);
if ($this->image_moo->errors) print $this->image_moo->display_errors();
$this->image_moo->clear();
}
}
}
}
希望這將有助於其他人在同樣的問題上苦苦掙扎。 如果你看到任何可以改進的地方,請告訴我。但是這對我很好。
馬克
如果您有與iPhone/iPad的ECT圖像處理,然後做出一個數據庫中的筆記的方法對其進行了翻轉然後翻轉圖像翻轉回發送給用戶之前,還是讓用戶選項在下載之前選擇方向/查看它不是你的錯誤用戶以錯誤的方向添加圖像。 –
我花了最近3天試圖弄清楚這一點。我想要的只是顯示上傳的iphone圖像的方式。如果我將圖像旋轉到在計算機屏幕(pc或macbook)上正確顯示,則很好,但在iphone/ipad上查看時圖像方向已關閉。我只是使用PHP來顯示存儲在我的服務器上的圖像,但我找不到一個不那麼簡單的答案。我已經閱讀了數百篇文章,並且有數百篇鏈接。谷歌甚至提供了我的原始文章(上週五,我發佈後20分鐘 - 去圖)。我需要成爲IOS程序員嗎? – Mark
好的,這是一個臨時的膠帶解決方案,但我用jhead -norot清除exif旋轉標籤。如果有人有更好的建議,我很樂意聽到它。 – Mark