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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pioneer-canvas-utils

v1.0.6

Published

签名、水印、文件转换为base64、下载图片等工具

Downloads

12

Readme

工具集合

  • 方法库

    • fileToBse64 将图片文件转换为 base64 码
    • downloadImg 下载图片
  • 签名

    • 封装的一个 ts 签名库,PC 端、移动端通用,支持签名,签名回显,保存签名区域为 png 图片等功能
  • 图片添加水印

    • 将图片添加水印,可以设置水印文字,水印图片,水印位置,水印透明度等

react 使用样例

  • https://gitee.com/jun96/pioneer-canvas-utils-example

方法库

  • fileToBase64 将文件转换为 base64 码
import {fileToBase64} from 'pioneer-canvas-utils'

const file = e.target.files[0]  // 获取图片file对象
const base64 = await fileToBase64(file)
console.log('base64', base64)
  • downloadImg
import {downloadImg} from 'pioneer-canvas-utils'

const url = 'base64'
const name = 'xxx.jpg'
downloadImg(url, name)

签名

import {Sign} from 'pioneer-canvas-utils'

const optins = {
	canvas,
	tracks,
	isEdit,
	color,
	lineHeight
}
const sign = new Sign(optins)

const signData = sign.getSignData()
sign.saveToImg(name)
sign.revoke()
sign.clear()
sign.destroy()

文档

options 参数

| 参数名 | 是否必须 | 描述 | 默认值 | 类型 | | ---------- | -------- | -------------- | ------ | ------- | | canvas | 是 | canvas dom | -- | -- | | tracks | 否 | 回显的签名数据 | -- | -- | | isEdit | 否 | 是否可以编辑 | true | boolean | | color | 否 | 签名颜色 | black | string | | lineHeight | 否 | 签名线宽 | 1 | number |

方法

| 方法名 | 描述 | 入参 | return | | --------------- | -------------------------------- | ------------------ | -------- | | getSignData() | 获取签名数据 | 无 | 签名数据 | | getImgBase64() | 获取签名图片的 base64 码 | 无 | base64 | | saveToImg(name) | 将签名最小区域保存为 png 图片 | name:保存的文件名 | 无 | | revoke() | 撤销最后一笔 | 无 | 无 | | clear() | 清空签名 | 无 | 无 | | destroy() | 销毁 Sign 中的事件,避免内存泄漏 | 无 | 无 |

图片添加水印

import {Watermark} from 'pioneer-canvas-utils'

const options = {
	url: string; // 图片http地址或base64
  text: string; // 水印文字
  angle?: number; // 水印文字倾斜角度
  fillStyle?: string; // 水印文字颜色
  fontSize?: number; // 水印文字大小
  gap?: number; // 水印文字间隙系数
}
const base64 = await Watermark.create(options)
console.log('添加水印后的图片', base64)

文档

options 参数

| 参数名 | 是否必须 | 描述 | 默认值 | 类型 | | --------- | -------- | ----------------------- | ------------------ | ------ | | url | 是 | 图片 http 地址或 base64 | -- | string | | text | 是 | 水印文字 | -- | string | | angle | 否 | 水印文字倾斜角度 | -15 | number | | fillStyle | 否 | 水印文字颜色 | rgba(0, 0, 0, 0.2) | string | | fontSize | 否 | 水印文字大小 | 12 | number | | gap | 否 | 水印文字间隙系数 | 20 | number |

静态方法

| 事方法名 | 描述 | 入参 | 返回 | | -------- | --------------------------- | ------- | ------------------------------------ | | create | 获取加好水印后的图片 base64 | options | promise 返回加好水印后的 base64 图片 |