本文主要是介绍ios版本小于13.4.1的手机需要前端对其调整图片方向,上传拍照照片总是方向不对,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这类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”);
}
这篇关于ios版本小于13.4.1的手机需要前端对其调整图片方向,上传拍照照片总是方向不对的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!