Introducing a user-friendly library for camera features in Svelte! This library provides a hassle-free way to capture both images and videos. With its intuitive controls such as start, stop, play, pause, captureImage, startVideoRecording, stopVideoRecording, autoOpen camera, mirrorDisplay, you can effortlessly customize your camera settings. The best part? This library does not require any additional dependencies.
npm install @cloudparker/easy-camera-svelte --save-dev
<script lang="ts">
import EasyCamera from '$lib';
let width = 600;
let camera: EasyCamera;
let mirrorDisplay = true;
const handleImage = async () => {
let imageData = await camera.captureImage();
console.log(imageData);
};
const handleVideo = async () => {
let blob = await camera.startVideoRecording();
if (blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'video.mp4';
document.body.appendChild(a);
a.click();
}
};
</script>
<div>
<EasyCamera bind:width style="border-radius:5px;" bind:this={camera} autoOpen bind:mirrorDisplay />
</div>
<button class="" type="button" on:click={() => camera.open()}>Start Camera</button>
<button class="" type="button" on:click={() => camera.close()}>Stop Camera</button>
<button class="" type="button" on:click={() => camera.pause()}>Pause</button>
<button class="" type="button" on:click={() => camera.resume()}>Resume</button>
<button class="" type="button" on:click={() => (mirrorDisplay = !mirrorDisplay)}>
{mirrorDisplay ? 'Disbale' : 'Enable'} Mirror Display
</button>
<button class="" type="button" on:click={handleImage}>Capture Image</button>
<button class="" type="button" on:click={handleVideo}>Start Video recording</button>
<button class="" type="button" on:click={()=> camera.stopVideoRecording()}>Stop Video recording</button>
Default: 340
Set width of the camera view, it automatically adjust the height of camra view based on the camera aspect ratio.
Style of the video view or camra view
Default: true
Enable or Disable mirror display of the video
Default: true
Use front camera while lunching the camera view
Default : true
User audio in video recording.
Default : false
Incase you need all video frame data in the form of ImageData enable this option. The frame data will be publish on:frame
event.
Trigger when camra init, return all camera devide infos array.
Trigger when video recording stop, it return a video Blob data.
Trigger whhen video recording start
Trigger when video Recording Stopped.
Triggered when image captured done, retrun with ImageData object or base64 image data, based on user request.
Trigger when camera oppend.
Trigger when camra closed/stopped.
Trigger when camera paused.
Trigger when camera resumed.
Trigger everytime a frame rendered, it will call very frequently with ImageData object. Use the frame data for your external use.
Open camera.
Close camera.
Pause camera.
Resume camra.
Start video recording and return video data Blob
format.
Stop video recording
Capture Image using camera. Pass isImageData when required ImageData
instead of base64.
Check is recording .
Request to switch camera.
Get all camera devices array