npm.io
1.0.7 • Published 2 years ago

mugshot-js

Licence
ISC
Version
1.0.7
Deps
0
Size
24 kB
Vulns
0
Weekly
0

mugshot-js

The mugshot-js library provides a JavaScript/TypeScript SDK for interfacing with the Mugshot.dev API, allowing easy integration of face recognition capabilities into your web applications.

Features

  • Add faces to Mugshot.dev for recognition.
  • Search for faces using uploaded images.
  • Delete faces from Mugshot.dev.

Installation

You can install mugshot-js using npm or yarn:

npm install mugshot-js

or

yarn add mugshot-js

Usage

Using the library in browser
import {MugshotClient} from 'mugshot-js';

const client = new MugshotClient('YOUR_API_KEY');

document
	.getElementById('fileInput')
	.addEventListener('change', async function (event) {
		const file = event.target.files[0];
		const metadata = {name: 'John Doe'};

		try {
			const response = await client.addFace(file, metadata);
			console.log(response);
		} catch (error) {
			console.error(error);
		}
	});
Using the library in Edge Environment
import {MugshotClient} from 'mugshot-js';

const client = new MugshotClient('YOUR_API_KEY');

const payload = await request.formData();
const file = payload.get('image');
const metadata = {name: 'John Doe'};

try {
	const response = await client.addFace(file, metadata);
	console.log(response);
} catch (error) {
	console.error(error);
}
Using the library with NodeJS
import {MugshotClient} from 'mugshot-js';

const client = new MugshotClient('YOUR_API_KEY');

const payload = await request.formData();
const file = fs.openAsBlob('person-image.jpg');
const metadata = {name: 'John Doe'};

try {
	const response = await client.addFace(file, metadata);
	console.log(response);
} catch (error) {
	console.error(error);
}

Keywords