vue-camera-kit
Version:
A versatile Vue 3 camera component for capturing photos and videos with advanced features
143 lines (109 loc) ā¢ 3.36 kB
Markdown
3 camera component for capturing photos and videos with advanced features.
[](https://www.npmjs.com/package/vue-camera-kit)
[](https://github.com/parsajiravand/vue-camera-kit)
Try out the live demo: [Vue Camera Kit Demo](https://vue-camera-kit.netlify.app/)
š¦ [NPM Package](https://www.npmjs.com/package/vue-camera-kit)
š [GitHub Repository](https://github.com/parsajiravand/vue-camera-kit)
- šø Photo Capture
- š„ Video Recording with Audio
- š Camera Switching (Front/Back)
- š Customizable Resolution
- š¼ļø Preview & Retake
- šØ Modern UI with Customizable Styling
## Installation
```bash
npm install vue-camera-kit
# or
yarn add vue-camera-kit
```
## Usage
### Global Registration
```typescript
import { createApp } from 'vue'
import VueCameraKit from 'vue-camera-kit'
import App from './App.vue'
const app = createApp(App)
app.use(VueCameraKit)
app.mount('#app')
```
```vue
<script setup lang="ts">
import Camera from 'vue-camera-kit'
</script>
<template>
<Camera
:width="640"
:height="480"
facing-mode="environment"
:photo-quality="0.92"
@photo-captured="onPhotoCaptured"
@video-stopped="onVideoStopped"
/>
</template>
```
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| width | number | 640 | Camera viewport width |
| height | number | 480 | Camera viewport height |
| facingMode | 'user' \| 'environment' | 'environment' | Camera facing mode |
| photoQuality | number | 0.92 | JPEG quality (0-1) |
| videoConstraints | MediaTrackConstraints | {} | Additional video constraints |
| showPreviewByDefault | boolean | true | Show preview after capture |
| Event | Payload | Description |
|-------|---------|-------------|
| photo-captured | { dataUrl: string, blob: Blob } | Emitted when photo is captured |
| video-started | - | Emitted when video recording starts |
| video-stopped | { blob: Blob } | Emitted when video recording stops |
| error | Error | Emitted on camera/recording errors |
```vue
<script setup lang="ts">
import Camera from 'vue-camera-kit'
import type { PhotoCaptureData, VideoCaptureData } from 'vue-camera-kit'
const onPhotoCaptured = ({ dataUrl, blob }: PhotoCaptureData) => {
// Handle captured photo
console.log('Photo captured:', { dataUrl, blob })
}
const onVideoStopped = ({ blob }: VideoCaptureData) => {
// Handle recorded video
console.log('Video recorded:', { blob })
}
</script>
<template>
<Camera
:width="1280"
:height="720"
facing-mode="user"
:photo-quality="0.95"
@photo-captured="onPhotoCaptured"
@video-stopped="onVideoStopped"
@error="(error) => console.error(error)"
/>
</template>
```
The component comes with default styling but can be customized using CSS variables or overriding classes:
```css
.vue-camera-kit {
/* Custom styles */
}
.camera-controls {
/* Custom control styles */
}
.control-btn {
/* Custom button styles */
}
```
- Chrome (Desktop & Mobile)
- Firefox (Desktop & Mobile)
- Safari (Desktop & Mobile)
- Edge (Desktop & Mobile)
MIT License
A versatile Vue