1.0.1 • Published 5 months ago

ngx-snap-cam v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

ngx-snap-cam

A lightweight, customizable Angular camera component for capturing photos directly from the browser.

npm version License: MIT

Features

  • 📸 Easy photo capture
  • 🎨 Customizable snap button
  • 📱 Front/rear camera support
  • 🖼️ Configurable resolution
  • 🎯 Standalone component
  • 💪 TypeScript support

Demo

Try it out: Live Demo

Installation

npm install ngx-snap-cam

Usage

import { NgxSnapCamComponent } from 'ngx-snap-cam';

@Component({
  // ...
  imports: [NgxSnapCamComponent],
  // ...
})

Basic Usage

<ngx-snap-cam 
  [facingMode]="'user'"
  [idealX]="1200"
  [idealY]="700"
  (snapTaken)="onPhotoTaken($event)">
</ngx-snap-cam>

Custom Snap Button

<ngx-snap-cam (snapTaken)="onPhotoTaken($event)">
  <ng-template #customButton let-snap>
    <button (click)="snap()">Custom Snap Button</button>
  </ng-template>
</ngx-snap-cam>

API Reference

Inputs

InputTypeDefaultDescription
facingMode'user'/'environment''user'Camera facing mode
idealXnumber1200Ideal width of the camera output
idealYnumber700Ideal height of the camera output

Outputs

OutputTypeDescription
snapTakenstringEmits base64 encoded image when snap is taken

Example

export class AppComponent {
  onPhotoTaken(photoData: string) {
    console.log('Photo taken:', photoData);
    // Handle the photo data (base64 string)
  }
}

Browser Support

Works in all modern browsers that support the WebRTC API:

  • Chrome
  • Firefox
  • Safari
  • Edge

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.