# mk-screencapture

> 网页截屏工具

Latest version **1.0.0** (published 2020-10-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install mk-screencapture
pnpm add mk-screencapture
yarn add mk-screencapture
bun add mk-screencapture
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-10-09 |
| First published | 2020-10-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 328 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zboy |
| Maintainers | zboy |
| Keywords | 屏幕截图, 截屏, html2canvas, screencapture |

## Links

- npm: https://www.npmjs.com/package/mk-screencapture
- npm.io page: https://npm.io/package/mk-screencapture

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-10-09

## README

## 该插件用来做网页内截图，是对 html2canvas.js 的升级

### 1. 增加图片跨域功能 （1.0.0 版本及以后）
### 2. 增加视频截图功能 （1.0.0版本以后）

## 使用

---


#### 1. 安装

```
  npm i screencapture -S
```

#### 2. 组件内使用

```
  import screenCapture from 'mk-screencapture'

   screenCapture(
    ele,
    {
      useCORS: true, // 允许图片跨域
    }).then(function (canvas) {
      const _baseImg = canvas.toDataURL()  // 转base64
      // do next
    })
```

#### 3. 视频引用时自动生成首屏截图

```
  function setVideoPoster(videoEle) {
    videoEle.addEventListener('loadeddata',()=>{  // javascript
      // $(videoEle).on('loadeddata', () => { // jquery
      var canvas = document.createElement("canvas"); //canvas画布
      const size = getComputedStyle(videoEle)
      canvas.width = Number(size.width.replace('px', ''));
      canvas.height = Number(size.height.replace('px', ''));
      canvas.getContext('2d').drawImage(videoEle, 0, 0, canvas.width, canvas.height);
      videoEle.setAttribute("poster", canvas.toDataURL("image/png"));
    })
  }
```


#### 4. 其他

其他配置请查看 [html2canvas 官网](http://html2canvas.hertzen.com/configuration)

#### 鸣谢

感谢 [html2canvas.js](http://html2canvas.hertzen.com/)

---
_Source: https://npm.io/package/mk-screencapture · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
