Hi all,
How to open camera for image upload in HTML?
When i click a button camera should open and i will capture an image. Then the captured image will be used for uploading.
Hi makenzi.exc,
Refer below example.
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } table { border: 1px solid #ccc; } table th { background-color: #F7F7F7; color: #333; font-weight: bold; } table th, table td { padding: 5px; border-color: #ccc; } </style> </head> <body> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.26/webcam.js"></script> <script type="text/javascript"> $(function () { Webcam.set({ width: 320, height: 240, image_format: 'jpeg', jpeg_quality: 90 }); Webcam.attach('#webcam'); $("#btnCapture").click(function () { Webcam.snap(function (data_uri) { $("#imgCapture")[0].src = data_uri; }); }); }); </script> <table border="1" cellpadding="0" cellspacing="0"> <tr> <td> <div id="webcam"></div> </td> <td> <img id="imgCapture" /> </td> </tr> <tr> <td align="center" colspan="2"> <input type="button" id="btnCapture" value="Capture" /> </td> </tr> </table> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.