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

canvas-poster-sprite

v1.0.5

Published

A poster plugin that can draw texts, paths and pictures to canvas, and export picture data.

Downloads

12

Readme

canvas-poster-sprite

A poster plugin that can draw texts, paths and pictures to canvas, and export picture data.

Introduction | 简体中文

Notes

  • Text does not support art form, art form can be replaced by pictures.
  • Pictures resources support | HTTPS (HTTP attention to the problem of cross domain), only the web side support local resources (local service, please use the require import).
  • Pictures(preload=true),can be first drawed to canvas.
  • The width and height of the canvas should be the same as the width and height of the poster image, so that the final composite image will not have excess white space.
  • The quality of exported images can be controlled through fields FileType and Quality. Generally, the quality of JPEG images is relatively low.
  • Inside uni, we call uni's API, it should be support app-vue, web and miniprogram.

Useage

  • install:npm i canvas-poster-sprite or yarn add canvas-poster-sprite
  • web:import CanvasPosterSprite from 'canvas-poster-sprite'
  • uni:import CanvasPosterSprite from 'canvas-poster-sprite/dist/uni-canvas-poster-sprite.js'
  • wx:import CanvasPosterSprite from 'canvas-poster-sprite/dist/wx-canvas-poster-sprite.js'
  • my:import CanvasPosterSprite from 'canvas-poster-sprite/dist/my-canvas-poster-sprite.js'
  • tt:import CanvasPosterSprite from 'canvas-poster-sprite/dist/tt-canvas-poster-sprite.js'
  • swan:import CanvasPosterSprite from 'canvas-poster-sprite/dist/swan-canvas-poster-sprite.js'
  • qq:import CanvasPosterSprite from 'canvas-poster-sprite/dist/qq-canvas-poster-sprite.js'
  • instance:new CanvasPosterSprite(setting)
new CanvasPosterSprite({
  /* uni|wx|my|tt|swan|qq */
  self: this, 
  canvasId: 'canvas-id',

  /* web|uni|wx|my|tt|swan|qq */
  width: 900,
  height: 1600,
  bgColor: '#dddddd',
  paths : {
    circle : [
      {x: 214, y: 1123, w: 56, h: 56, r: 28, type: "fill", color: "#ffffff"}
    ],
    rect : [
      {x: 324, y: 1209, w: 252, h: 252, type: "fill", color: "#e6e6e6"},
      {x: 325, y: 1210, w: 250, h: 250, type: "fill", color: "#ffffff"},
      {x: 206, y: 1117, w: 488, h: 68, r: 34, type: "fill", color: "rgba(0, 0, 0, .15)"},
      {x: 376.5, y: 1520.5, w: 152, h: 44, r: 22, lineWidth: 4, color: "#000000"}
    ],
    triangle : [
      {points : [{x: 450, y: 1198}, {x: 462, y: 1185}, {x: 439, y: 1185}], type: "fill", color: "rgba(0, 0, 0, .15)"}
    ],
    line : [
      {x1: 360, y1: 1490.5, x2: 400, y2: 1490.5, lineWidth: 2, color: "#000000"},
      {x1: 505, y1: 1490.5, x2: 545, y2: 1490.5, lineWidth: 2, color: "#000000"}
    ]
  },
  /*pics : [
    {x: 0, y: 0, w: 900, h: 1600, preload: true, src: "./img/bg-zm.jpg"},
    {x: 328, y: 1213, w: 244, h: 244, src: "./img/qrcode-zm.png"},
    {x: 215, y: 1124, w: 54, h: 54, r: 27, src: "./img/icon.jpeg"}
  ],*/
  texts: [
    {x: 280, y: 1152, font: "26px 微软雅黑", color: "#FFE506", text: "小小咖侠侣店"},
    {x: 436, y: 1152, font: "26px 微软雅黑", color: "#ffffff", text: "邀请你注册侠侣联盟"},
    {x: 328, y: 1493, w: 250, font: "24px 微软雅黑", align: "center", color: "#000000", text: "邀 请 码"},
    {x: 328, y: 1543, w: 250, font: "28px Arail", align: "center", color: "#000000", text: "3ZGVTV"}
  ]
}).then((err, res)=>{
   if(err){
     console.log("canvas-fail:", err);
     return;
   }
   let { tempFilePath, canvas } = res;
   console.log("canvas-success:", res);
})

examples

Configuration

  • let spriter = new CanvasPosterSprite(options)
  • options
  • web | uni | wx | my | tt | swan | qq

| param | type | require | default | desc | | :----: | :----: | :----: | :----: | :---- | | width | Number | -- | 640 | canvas width. | | height | Number | -- | 640 | canvas height. | | bgColor | String | -- | #fff | canvas background color. | | fileType | String | -- | jpeg | type of pictures. eg.jpeg、png、gif | | quality | Number | -- | 1 | quality of pictures. | | pics | Array | -- | -- | pictures. More | | paths | Object | -- | -- | paths. More | | texts | Array | -- | -- | texts. More |

  • uni | wx | my | tt | swan | qq

| param | type | require | default | desc | | :----: | :----: | :----: | :----: | :---- | | self | Object | yes | -- | content - this | | canvasId | String | yes | -- | canvas-id |

  • uni

| param | type | require | default | desc | | :----: | :----: | :----: | :----: | :---- | | appPlus | Boolean | -- | false | app,whether transform pictures to base64 first,and draw to canvas,fix:Android10 uni.canvasToTempFilePath Error. | | pixelRatio | Number | -- | 2 | app pixelRatio. |

  • spriter

| method | desc | | :----:| :---- | | spriter.then(callback) | callback(err, res) |