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

weapp-canvas-poster

v1.0.11

Published

<!-- * @Descripttion: * @FilePath: /weapp-canvas-poster/README.md * @Author: 张兴业 * @Date: 2021-10-28 21:00:18 * @LastEditors: 张兴业 * @LastEditTime: 2021-10-28 21:43:01 --> # 微信小程序canvas绘制海报

Downloads

16

Readme

微信小程序canvas绘制海报

安装方式 - npm

npm install weapp-canvas-poster --save

使用方法

wxml

<canvas id="share-poster" type="2d" style="width: {{dWidth * dpr}}px; height: {{dHeight * dpr}}px; background: {{background}};"></canvas>

dWidth: cavans宽度(单倍图) dHeight: cavans宽度(单倍图) dpr: 设备像素比 background: canvas背景色(此背景色必须与creatPoster中canvasOptions.background背景色保持一致,否则会找到生成的海报黑屏) 若需要生成二维码,需添加以下代码

<canvas id="share-qrcode" type="2d" style="width: 200px; height: 200px"></canvas>

wxss

canvas {
  position: absolute;
  left: -20000px;
}

js

import { createPoster, PosterType, savePoster, sharePoster } from 'weapp-canvas-poster';

PosterType canvas绘制元素类型 PosterType.Text: 文本类型 PosterType.Image: 图片类型 PosterType.QRCode: 二维码类型 createPoster 生成海报

createPoster({
  canvasId: '#share-poster',
  dpr: 2,
  canvasOptions: {
    background: '#fff', // 必须与canvas背景色保持一致,否则会找到生成的海报黑屏
  },
  list: [
    {
      type: PosterType.Text, // 文本类型
      x: dWidth / 2, // x坐标
      top: 24, // 距顶部距离(y坐标)
      lineHeight: 20, // 行高
      width: dWidth - 24, // 宽度
      fontSize: 14, // 字体大小
      fontWeight: 400, // 文本粗细
      fontFamily: 'PingFang', // 字体
      fillStyle: '#000', // 文字颜色
      textAlign: 'center', // 文本排列
      content: '我们是共产主义接班人!' // 文本内容
    },
    {
      type: PosterType.Image, 图片类型
      x: (dWidth - 101) / 2, // x坐标
      y: 30, // y坐标
      width: 101, // 宽度
      height: 33, // 高度
      src: 'https://www.baidu.com/img/flexible/logo/pc/[email protected]' // 图片url
    },
    {
      type: PosterType.QRCode, // 二维码类型
      x: 80, // x坐标
      y: 80, // y坐标
      width: 160, // 宽度
      height: 160, // 高度
      src: "我们是共产主义接班人!", // 二维码内容
      logo: 'https://assets-img.myazstore.com/miniprogram/aoxingou/images/icons/logo.png', // 二维码logo
      canvasId: '#share-qrcode' // 二维码canvasId
    },
  ]
}, this).then(filePath => {
  // filePath 绘制海报生成图片临时地址,用来展示
  this.setData({
    filePath
  })
}).catch(err => {});

savePoster 保存图片 filePath: createPoster返回的图片临时地址

savePoster(filePath).then((res) => {
  console.log(res);
}).catch(() => {});

sharePoster 分享图片 filePath: createPoster返回的图片临时地址

sharePoster(filePath).then((res) => {
  console.log(res);
}).catch(() => {});