JS Wrapper to allow taking photo with the HTML media API. It can be used on desktop, tablet or smartphone. On IOs devices, it uses an hidden input file with accept tag so that propose to use the camera.
If you want to use it on production you will have to access the website under the HTTPS protocol. Otherwise, most navigators block the access to the userMedia
- import photoWrapper.js in the file you need it
- create a new instance of the plugin calling
new photoWrapper.photoWrapper(elt,width,height,afterInit,onImportPhoto);
- store the instance to be able to call plugin's methods
afterInit()
is a callback called after the plugin's initializationonImportPhoto(dataUrl)
is a callback called after the user imported a photo thanks to the input file, the plugin use the HTML5 File API to load the image without sending it to a server but directly in the DOM. So you can access the image as a dataUrl with the vardataUrl
start()
: start the camera to be able to take a photostop()
: stop the camera (if you don't need it anymore)getPhoto()
: return the photo as a dataUrlgetVideo()
: return the videoElement used to display the camera previewtriggerInputFileClick()
: trigger the input file click to allow user to import a photohasAccessToMedia()
: return true if the plugin can access userMedia and use camerascanSwitchSources()
: return true if there is more than one source for the camera (for example: front and back for a smartphone)switchSource()
: switch to the next source if there are more than one sourcegetStream()
: return the camera stream
Examples are availables in the examples directory
Feel free to ask for request or to do pull request if you think you've improved the plugin
This piece of software is issued under the GNU GENERAL PUBLIC LICENSE. You can view the license here