I am making a simple web application on a mobile device that allows a visitor to take a photo using the [type = file] html5 input element. Then I will show it on the Internet for preview, and then the visitor can choose to upload the photo to his server for other purposes (for example: upload to FB)
I find the problem with the orientation of the photo when I take a photo using my iPhone and keep it upright. The photo is in the correct orientation in the tag. However, when I try to draw it in the canvas using the drawImage () method, it rotates 90 degrees.
I tried to take a photo in 4 directions, only one of them can draw the correct image in the canvas, the others are turned or even turned upside down.
Well, I'm confused to get the right orientation to fix this problem ... Thanks for helping ...
here is my code, basically a copy from MDN
<div class="container"> <h1>Camera API</h1> <section class="main-content"> <p>A demo of the Camera API, currently implemented in Firefox and Google Chrome on Android. Choose to take a picture with your device camera and a preview will be shown through createObjectURL or a FileReader object (choosing local files supported too).</p> <p> <form method="post" enctype="multipart/form-data" action="index.php"> <input type="file" id="take-picture" name="image" accept="image/*"> <input type="hidden" name="action" value="submit"> <input type="submit" > </form> </p> <h2>Preview:</h2> <div style="width:100%;max-width:320px;"> <img src="about:blank" alt="" id="show-picture" width="100%"> </div> <p id="error"></p> <canvas id="c" width="640" height="480"></canvas> </section> </div> <script> (function () { var takePicture = document.querySelector("#take-picture"), showPicture = document.querySelector("#show-picture"); if (takePicture && showPicture) { </script>
javascript html5 html5-canvas canvas drawimage
Rock Yip Oct 19 '13 at 6:27 2013-10-19 06:27
source share