这类iphone中手机竖着拿然后逆时针旋转90°才是正确的拍照姿势
这时候拍出来的照片展示在canvas中是不会被旋转的。如果以其他角度拍照时,就会发生旋转。
function imgToCanvasWithOrientation(img, width, height, orientation) {let canvas = document.createElement("canvas");let ctx = canvas.getContext("2d");canvas.width=widthcanvas.height=heightif (判断机型系统不高于ios13.4.1) {switch (orientation) {case 3:ctx.rotate(Math.PI)ctx.drawImage(img, -width, -height, width, height);break;case 6:ctx.rotate(0.5 * Math.PI)ctx.drawImage(img, 0, -height, width, height);break;case 8:ctx.rotate(3 * Math.PI / 2)ctx.drawImage(img, -width, 0, width, height);break;default:ctx.drawImage(img, 0, 0, width, height);break}}return canvas.toDataURL(“image/png”);
}