Created
May 13, 2019 10:37
-
-
Save annaliahsiao/edbe1bfa76d8f945b9c35b55c5dc8cf2 to your computer and use it in GitHub Desktop.
照片預覽與取得照片資訊、照片旋轉功能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function img_load(_this){ | |
if(_this.files && _this.files[0]){ | |
var reader = new FileReader(); | |
//獲取照片方向角屬性,使用者旋轉控制 | |
EXIF.getData(_this.files[0], function(e) { | |
//orientation表示取得照片的角度,EXIF.getTag()表示取得照片的指定參數數據 | |
var orientation = EXIF.getTag(this, 'Orientation'); | |
//exifdata.DateTime表示取得照片的拍攝時間 | |
var photo_time = this.exifdata.DateTime; | |
reader.onload = function(e) { | |
var rotateAngle = 0; | |
if(orientation == 6 || orientation == 8|| orientation == 3){ | |
switch(orientation){ | |
case 3: | |
//照片旋轉180度 | |
rotateAngle = 180; | |
break; | |
case 6: | |
//照片向左旋轉90度 | |
rotateAngle = 90; | |
break; | |
case 8: | |
//照片向右旋轉90度 | |
rotateAngle = -90; | |
break; | |
} | |
} | |
$('#photo_demo_canvas').css({'background-image':'url('+event.target.result+')','transform':'rotate('+rotateAngle+'deg)'}); | |
} | |
reader.readAsDataURL(_this.files[0]); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment