PHP Webcam Capture Image Save from Camera using jQuery

Today, We want to share with you PHP Webcam Capture Image Save from Camera using jQuery.In this post we will show you Capture Webcam Image with PHP and jQuery, hear for PHP Webcam Capture Image Database PHP Script to take Photo we will give you demo and example for implement.In this post, we will learn about capture image using webcam and save to database in php and html5 with an example.

PHP Webcam Capture Image Save from Camera using jQuery

There are the Following The simple About PHP Webcam Capture Image Save from Camera using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop capture image from webcam and store in database in php, so the some major files and Directory structures for this example is following below.

  • index.php
  • saveUploadImg.php
Also Read :  jQuery Capture Webcam Image Using Web Camera in PHP

Step 1 : HTML Configuration and User Interface

index.php

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.

<!DOCTYPE html>
<html>
<head>
    <title>Capture webcam image with php and jquery - pakainfo.com</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.25/webcam.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
    <style type="text/css">
        #preview { padding:30px; border:1px solid; background:#3d3d3d; }
    </style>
</head>
<body>
  
<div class="container">
    <h1 class="text-center">Capture webcam image with php and jquery - pakainfo.com</h1>
	<p>Integrate Webcam Capture in a PHP Application</p>
    <form method="POST" action="saveUploadImg.php">
        <div class="row pakainfo">
            <div class="col-md-6 pakainfo">
                <div id="live_camera"></div>
                <hr/>
                <input type=button value="Take Snapshot" onClick="capture_web_snapshot()">
                <input type="hidden" name="image" class="image-tag">
            </div>
            <div class="col-md-6">
                <div id="preview">Your captured image will appear here...</div>
            </div>
            <div class="col-md-12 text-center pakainfo">
                <br/>
                <button class="btn btn-primary pakainfo">Submit</button>
            </div>
        </div>
    </form>
</div>
  
<!-- Settings a few settings and (php capture image from camera) web attach camera -->
<script language="JavaScript">
    Webcam.set({
        width: 490,
        height: 390,
        image_format: 'jpeg',
        jpeg_quality: 90
    });
  
    Webcam.attach( '#live_camera' );
  
    function capture_web_snapshot() {
        Webcam.snap( function(site_url) {
            $(".image-tag").val(site_url);
            document.getElementById('preview').innerHTML = '<img src="'+site_url+'"/>';
        } );
    }
</script>
 
</body>
</html>

Step 2 : Save and Upload Images

saveUploadImg.php

<?php
    
    $myimg = $_POST['image'];
    $destinationPath = "upload/";
  
    $web_capture_part = explode(";base64,", $myimg);
    $image_type_aux = explode("image/", $web_capture_part[0]);
    $image_type = $image_type_aux[1];
  
    $image_base64 = base64_decode($web_capture_part[1]);
    $myimgName = uniqid() . '.png';
  
    $file = $destinationPath . $myimgName;
    file_put_contents($file, $image_base64);
  
    print_r($myimgName);
  
?>

Angular 6 CRUD Operations Application Tutorials

Read :

Also Read :  How to Open URL in New Tab using EmberJS

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Webcam Capture Image Save from Camera using jQuery.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Recommended For You.

jQuery Capture Webcam Image Using Web Camera in PHP
Today, We want to share with you jQuery Capture Webcam Image Using Web Camera in PHP.In this post we will

Add a Comment

Your email address will not be published. Required fields are marked *