npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ar-glasses

v1.1.1

Published

AR library to overlay virtual glasses using webcam and face landmarks

Readme


👓 AR Glasses

A lightweight TypeScript library that overlays virtual glasses on detected faces using face-api.js and your device's camera.


Features

  • 🔍 Real-time face detection using your webcam
  • 🕶️ Overlay custom glasses images (supports URLs or file uploads)
  • 📦 Easy to integrate with any frontend app
  • 💡 Built with TypeScript and compatible with modern bundlers
  • 📁 Automatic model handling for face-api.js (no manual setup needed)

📦 Installation

Using npm or Yarn

To get started, install the package via npm or yarn:

npm install ar-glasses

Or with Yarn:

yarn add ar-glasses

Using a CDN

You can also use the library directly in the browser via a CDN. For example, using jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/ar-glasses/dist/ar-glasses.umd.js"></script>

This will expose the library as a global variable ARGlasses.


🚀 Usage

React Example

import React, { useRef, useEffect, useState } from 'react';
import { startGlassesOverlay } from 'ar-glasses';

const ARGlasses = () => {
  const videoRef = useRef<HTMLVideoElement>(null);
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const [glassesImage, setGlassesImage] = useState<string>('');

  useEffect(() => {
    if (videoRef.current) {
      navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
        videoRef.current!.srcObject = stream;
      });
    }
  }, []);

  const handleStart = () => {
    if (videoRef.current && canvasRef.current && glassesImage) {
      startGlassesOverlay(videoRef.current, canvasRef.current, glassesImage);
    } else {
      alert('Please upload a glasses image first!');
    }
  };

  const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const file = event.target.files?.[0];
    if (file) {
      const reader = new FileReader();
      reader.onload = () => setGlassesImage(reader.result as string);
      reader.readAsDataURL(file);
    }
  };

  return (
    <div>
      <input type="file" accept="image/*" onChange={handleFileChange} />
      <button onClick={handleStart}>Start</button>
      <video ref={videoRef} autoPlay muted playsInline width="640" height="480"></video>
      <canvas ref={canvasRef} width="640" height="480"></canvas>
    </div>
  );
};

export default ARGlasses;

Plain JavaScript Example (Using CDN)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>AR Glasses Example</title>
    <script src="https://cdn.jsdelivr.net/npm/ar-glasses/dist/ar-glasses.umd.js"></script>
    <script>
      document.addEventListener('DOMContentLoaded', () => {
        const video = document.getElementById('video');
        const canvas = document.getElementById('overlay');
        const uploadInput = document.getElementById('glasses-upload');
        const startButton = document.getElementById('start');

        let glassesImageDataURL = '';

        navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
          video.srcObject = stream;
        });

        uploadInput.addEventListener('change', (e) => {
          const file = e.target.files?.[0];
          if (file) {
            const reader = new FileReader();
            reader.onload = () => {
              glassesImageDataURL = reader.result;
            };
            reader.readAsDataURL(file);
          }
        });

        startButton.addEventListener('click', () => {
          if (glassesImageDataURL) {
            ARGlasses.startGlassesOverlay(video, canvas, glassesImageDataURL);
          } else {
            alert('Please upload a glasses image first!');
          }
        });
      });
    </script>
  </head>
  <body>
    <input type="file" id="glasses-upload" accept="image/*" />
    <button id="start">Start</button>
    <video id="video" autoplay muted playsinline width="640" height="480"></video>
    <canvas id="overlay" width="640" height="480"></canvas>
  </body>
</html>

📂 Model Handling

AR Glasses automatically handles model loading for face-api.js. No additional setup is required. Simply upload or link to your preferred glasses image and let the library do the rest!


🧠 Powered By


📜 License

MIT License © 2025