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

xmediajs

v1.2.1

Published

基于HTML5的getUserMedia API的实现的拍照js库,支持添加引导框并自动裁剪,支持扫描抓拍效果,支持图片压缩和旋转,同时支持降级使用input file进行拍摄。

Readme

xmedia

介绍

基于HTML5的getUserMedia API的实现的拍照js库,支持添加引导框并自动裁剪,支持扫描抓拍效果,支持图片压缩和旋转,同时支持降级使用input file进行拍摄。

安装教程

 // npm 安装
 npm install xmediajs -S

 // 通过git地址安装过
 npm install https://gitee.com/hola/xmedia.git

使用说明


    // 使用前置摄像头拍照
    xmedia.startTakeFace({
        targetId: '#img',  // 渲染照片的目标img id
        needCompress: true, // 是否开启压缩
        success: function(data){
            // 拍照成功,data会返回照片的File对象和base64数据
            console.info('success...');
            console.info(data);
        }, 
        fail: function(err){
            // 拍照失败
            console.info('fail...');
            console.error(err);
        }
    });

    // 使用后置摄像头拍摄
    xmedia.startTakePhoto({
        targetId: '#img', 
        needCompress: true,
        success: function(data){
            console.info('success...')
            console.info(data);
        }, 
        fail: function(err){
            console.info('fail...')
            console.error(err)
        }
    })

    // 使用后置摄像头拍摄,并展示默认证件摆放引导框
    xmedia.startTakePhoto({
        targetId: '#img', 
        withGuide: true, // 是否展示证件引导框
        needCompress: false,
        success: function(data){
            console.info('success...')
            console.info(data);
        }, 
        fail: function(err){
            console.info('fail...')
            console.error(err)
        }
    })

    // 使用前置摄像头拍照,并支持选择文件和input file方式拍照
    xmedia.startTakeFace({
        targetId: '#img',
        tips:'温馨提示:请确保人脸完整',
        supportFile: true,
        defaultOri: 8, // 旋转-90度
        needRotate: true,
        fileBtnText: '选择文件',
        needCompress: true,
        success: function (data) {
            console.info('success...')
            console.info(data);
        },
        fail: function (err) {
            console.info('fail...')
            console.error(err)
        }
    }).then(() => {
        // console.info('摄像头准备就绪...')
    })

    // 单独请求录音audio权限
    xmedia.openAudio().then(()=>{
        console.info('麦克风成功授权..')
    })

    // 开始录音,一般是在openAudio成功后再调用,
    // 也可以直接调用请求授权并开始录音
    // 这里的success与fail均在xmedia.stopAudioRecord()后才执行
    xmedia.startAudioRecord({
        success: function(blob){
            console.info('结束录音...')
            console.info(blob)
            const audioURL = URL.createObjectURL(blob);
            document.querySelector("audio").src = audioURL;
        }, 
        fail: function(err){
            console.info('fail...')
            console.error(err)
        }
    })

    // 停止录音
    xmedia.stopAudioRecord();

自定义引导框说明

如果默认的引导框不符合实际需求,可设置不展示默认引导框,并自主添加引导框,引导框需采用固定fixed定位,且z-index设置成1005。

注意:拍摄组件z-index默认是从1000~1010,如果有其它组件的z-index大于1010会覆盖拍摄组件,开发者可利用大于1010的z-index添加其他覆盖效果。