2017-03-09 60 views
3

我正嘗試使用Samsung S7拍照並將其上傳到我的應用程序中。但圖片上傳時正在旋轉。即使我也從圖庫中選擇圖片,它也會在上傳時旋轉。有什麼我們可以從jquery代碼修復。請建議。在此先感謝上傳時默認情況下圖像正在旋轉

HTML:

<div class="photo-div" id="photo"> 
       <img id="uploadimage" src="" hidden=""> 
      </div> 

<label id="files-label" for="files" class=" myprofile-btn-bold">Replace Image</label> 
<input id="files" style="display:none;" type="file" accept="image/*" onchange="readURL(this);"> 

的Jquery:

function readURL(input) { 

    if (input.files && input.files[0]) { 
     var reader = new FileReader(); 

     reader.onload = function (e) { 
      $('#files-label').html('Replace Image'); 
      $('.photo-image').removeClass('photo-image'); 
      $('#uploadimage').attr('src', e.target.result); 
      $("#headshot-message").hide(); 
      $("#headshot-cancel").hide(); 
      $('#noimage-label').addClass('hidden'); 
     } 

     reader.readAsDataURL(input.files[0]); 
    } 
} 
+0

我們可以看到一段代碼,看看你是如何上傳它的嗎? – maksymiuk

+0

嗨@maksymiuk,請找到最新的問題。請讓我知道如果你需要更多的 –

+0

jquery非常簡單,沒有什麼真正脫穎而出,會導致圖像旋轉。當你將e.target.result附加到#uploadimage元素時,你正在上傳到服務器還是圖像旋轉? – KFE

回答

2

你的手機攝像頭的應用程序不轉身並保存圖像,你從你的角度看他們,但它只從方位傳感器上標記EXIF orientation data。這些信息由您的圖庫應用程序解釋,但您的瀏覽器將忽略它並按照傳感器視角顯示圖片。

你可以把圖片周圍根據服務器上的EXIF數據與imagemagick auto-orient

convert uploadedImage.jpg -auto-orient turnedImage.jpg 

或者在客戶端使用jQuery在這篇文章解釋說:

https://stackoverflow.com/a/28843763/2346308

+0

對於大尺寸圖像來說,它工作正常,但是在添加此實現之前不會發生較小尺寸的圖像旋轉。 –

+0

你使用了哪個實現,JQuery或ImageMagick?你可以檢查這些小圖像是否有適當的方向標誌設置爲大的?你可以使用這個網站:http://exif-viewer.com/ –

+0

使用JQuery一個 –