iphone对拍摄的照片有自动处理
//修复ios if (navigator.userAgent.match(/iphone/i)) { image.src = reader.result; image.onload=function(){ var degree=0,drawWidth,drawHeight,width,height; drawWidth=this.naturalWidth; drawHeight=this.naturalHeight; var canvas=document.createElement('canvas'); canvas.width=width=drawWidth; canvas.height=height=drawHeight; var context=canvas.getContext('2d'); //判断图片方向,重置canvas大小,确定旋转角度,iphone默认的是home键在右方的横屏拍摄方式 switch(Orientation){ //iphone横屏拍摄,此时home键在左侧 case 3: degree=180; drawWidth=-width; drawHeight=-height; break; //iphone竖屏拍摄,此时home键在下方(正常拿手机的方向) case 6: canvas.width=height; canvas.height=width; degree=90; drawWidth=width; drawHeight=-height; break; //iphone竖屏拍摄,此时home键在上方 case 8: canvas.width=height; canvas.height=width; degree=270; drawWidth=-width; drawHeight=height; break; } //使用canvas旋转校正 context.rotate(degree*Math.PI/180); context.drawImage(this,0,0,drawWidth,drawHeight); var url=canvas.toDataURL("image/jpeg",1); $image.attr("src", url); $image.cropper('replace', url); }