AyrA icon

Simple HTML5 Camera Photo Capture

AyrA | PRO | 08/24/18 02:02:08 PM UTC | 0 ⭐ | 516 👁️ | Never ⏰ | []
HTML 5 |

0 B

|

None

|

0 👍

/

0 👎

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <video autoplay></video><br />
        <input type="button" value="snapshot" /><br />
        <canvas></canvas>
        <script type="text/javascript">
            (function () {
                //Video only
                var constraints = {
                    video: true
                };
                //Video element
                var video = document.querySelector('video');
                //Get camera
                navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
                    //assign stream to video element on success
                    video.srcObject = stream;
                });
                //Button click
                document.querySelector("[type=button]").addEventListener("click", function () {
                    //Get empty canvas element
                    var canvas = document.querySelector("canvas");
                    //Set to video dimensions
                    canvas.width = video.clientWidth;
                    canvas.height = video.clientHeight;
                    //Grab snapshot and render it
                    var ctx = canvas.getContext("2d");
                    ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
                });
            })();
        </script>
    </body>
</html>

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎