Home Top Ad

Capture Photo from Mobile or Webcam using WebCam.js

 You can also use third-party webcam jQuery to capture live images from a webcam or mobile camera.


First download webcam.js from git

https://github.com/jhuckaby/webcamjs


put a reference like below on your HTML page.

<script src="/webcam/webcam.min.js"></script>


Put the below code on your head part of the HTML page.


  <script language="JavaScript">

    Webcam.set({

        width: 320,

        height: 240,

        dest_width: 640,

        dest_height: 480,

        image_format: 'jpeg',

        jpeg_quality: 90

    });

    Webcam.attach('#my_camera');



    var shutter = new Audio();

    shutter.autoplay = false;

    shutter.src = navigator.userAgent.match(/Firefox/) ? '/webcam/shutter.ogg' : '/webcam/shutter.mp3';


    function take_snapshot() {

        shutter.play();

        // take snapshot and get image data

        Webcam.snap(function (data_uri) {

            // display results in page

            document.getElementById('results').innerHTML =

                '<h2>Here is your large image:</h2>' +

                '<img src="' + data_uri + '"/>';

        });

    }

</script> 


Use the below code in your body.


<input type=button value="Take Large Snapshot" onClick="take_snapshot()">

<div id="my_camera"></div>

<div id="results">Your captured image will appear here </div>


Capture Photo from Mobile or Webcam using WebCam.js Capture Photo from Mobile or Webcam using WebCam.js Reviewed by Code Infosys on August 31, 2023 Rating: 5

Why you are not purchase ,At least Write in comment.

No comments