# p-camera-h5 **Repository Path**: xiangfz/p-camera-h5 ## Basic Information - **Project Name**: p-camera-h5 - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-04 - **Last Updated**: 2025-11-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # p-camera-h5 📷 [](https://github.com/pbstar/p-camera-h5) [](https://www.npmjs.com/package/p-camera-h5) [](https://bundlephobia.com/package/p-camera-h5) [](https://pbstar.github.io/p-camera-h5-demo/) 一款轻量级 H5 相机插件,支持拍照、录像、文字图片水印,适配现代浏览器,为 Web 应用提供原生级摄像头体验。 ## ✨ 核心特性 - **即时捕获** 📸 拍照、🎥 录像 - **水印** 🖼️ 支持文字内容、位置、颜色、字体大小、图片等 - **无缝集成** ⚡ 极简 API 设计、不依赖任何外部库 - **跨平台** 🌍 完整适配桌面端与移动端浏览器 ## 📦 安装 ### NPM ```bash npm install p-camera-h5 --save ``` ### CDN ```html ``` ## 🚀 快速接入 ```html
``` ```javascript import pCameraH5 from "p-camera-h5"; // 初始化 const camera = new pCameraH5({ el: document.querySelector("#el"), // 容器选择器 watermark: [ { x: 10, y: 10, text: "p-camera-h5", }, ], }); // 拍照 camera.capture().then((file) => { // 处理照片文件 console.log(file); }); // 录像 camera.startRecording().then((isSuccess) => { if (isSuccess) { // 开始录像 } }); // 停止录像 camera.stopRecording().then((file) => { // 处理视频文件 console.log(file); }); ``` ## ⚙️ 配置项 | 参数 | 类型 | 默认值 | 说明 | | ------------ | ----------- | ------------- | ----------------------------------------- | | `el` | HTMLElement | **必填** | 挂载容器元素 | | `facingMode` | string | `environment` | 摄像头方向,默认后置,可选 `user`(前置) | | `isAudio` | boolean | `false` | 是否开启音频录制,默认关闭 | | `isMirror` | boolean | `false` | 是否镜像反转,默认关闭 | | `watermark` | Watermark[] | null | 水印配置对象数组 | 水印配置对象说明: | 参数 | 类型 | 默认值 | 说明 | | ------ | ------------------------- | ------ | -------------------------- | | `x` | number | 10 | 水印 x 坐标 | | `y` | number | 28 | 水印 y 坐标 | | `text` | WatermarkText{} / string | - | 文字水印配置对象或字符串 | | `img` | WatermarkImage{} / string | - | 图片水印配置对象或图片 URL | 文字水印配置对象说明: | 参数 | 类型 | 默认值 | 说明 | | ---------- | ------ | -------------------------- | ------------ | | `text` | string | - | 文字内容 | | `fontSize` | number | 18 | 字体大小(px) | | `color` | string | `rgba(255, 255, 255, 0.5)` | 字体颜色 | 图片水印配置对象说明: | 参数 | 类型 | 默认值 | 说明 | | -------- | ------ | ------ | ------------ | | `url` | string | - | 图片 URL | | `width` | number | 100 | 图片宽度(px) | | `height` | number | 100 | 图片高度(px) | ## 📚 API 方法 | 方法 | 说明 | 返回值 | 示例 | | ------------------ | -------------------- | ---------------- | ------------------------- | | `capture()` | 拍摄照片 | Promise