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 🙏

© 2024 – Pkg Stats / Ryan Hefner

canvas2file

v1.0.4

Published

A lib for saving or converting canvas as file like img.

Downloads

8

Readme

🎨canvas2file

语言:English

<canvas>转化为<img>的Javascript库,轻而易举地转化和下载。

快速开始

npm引入

npm i canvas2file
import Canvas2File from 'canvas2file';

直接引入

1⃣️ 在body下引入canvas2file.js

<script src="canvas2file.js"></script>

2⃣️ 将你的JavaScript代码插入到canvas2file.js之下,以确保你在你的js文件内Canvas2File能被正确地识别。

使用说明

当引入canvas2file.js的时候,你就能愉快地使用Canvas2File对象了。

查看演示

Example:

Canvas2File.insertImg('canvas','box');
Canvas2File.insertImg('canvas','box',1);
Canvas2File.download('canvas');
Canvas2File.download('canvas','imageName');
Canvas2File.download('canvas','imageName','image/jpeg');

|方法名|简介| |:--|:--| |insertImg(canvasId,elementId,quality)|转化为<img>并插入到指定结点中。| |download(canvasId,fileName,type)|以图片格式下载<canvas>。|

insertImg(canvasId,elementId,quality)

<canvas/>转化为<img/>插入到指定结点中。

参数

  • canvasId

被操作的canvas的id

  • elementId

需要插入所转化<img/>的id

  • quality (可选)

图片质量,仅供在'image/jpeg'类型时使用

download(canvasId,fileName,type)

<canvas/>转化为img下载到本地。

参数

  • canvasId

被操作的canvas的id

  • fileName (可选)

下载到本地到图片文件。默认名image.png

  • type (可选)

图片类型。默认image/png,可选image/jpegimage/webp(webp仅在谷歌浏览器可使用)

常见问题

1、为什么导出的jpeg格式的图片背景是黑色?

如果你需要导出jpeg格式的图片,请在canvas绘制之初将背景色填充成白色,否则jpeg格式的图片背景色会变成黑色。

    context.fillStyle = 'white';
    context.fillRect(0,0,ctx.canvas.width,ctx.canvas.height);

参与共建

希望你也能参与到这个js库的建设中,欢迎你的加入。

License

MIT