0.1.19 • Published 1 year ago

@sh-rep/super-poster v0.1.19

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

微信小程序海报帮助工具(原生、uniapp、taro)

安装

# 注意!原生小程序中安装后还需要在开发者工具中构建npm
$ npm i @sh-rep/super-poster

起步

页面展示组件

原生小程序

  • 引入 在页面配置 json 中加入组件引用
{
  "usingComponents": {
    "PosterView": "@sh-rep/super-poster/components/mini/posterView/posterView"
  }
}
  • 使用
<!-- json为海报的配置json -->
<PosterView json="{{json}}" styles="自定义的style字符串" />

在 uniapp 中使用

  • 1、引入 在pages.json中添加 easycom
{
  "easycom":{
		"PosterView":"@sh-rep/super-poster/dist/components/uni/posterView.vue"
	}
}

使用

<!-- json为海报的配置json -->
<PosterView :json="json" styles="自定义的style字符串" />

在 Taro 中使用

import PosterView from '@sh-rep/super-poster/dist/components/taro/posterView';

function TestCom(){
  // json为海报的配置json
  return <PosterView json={json} styles="自定义的style字符串">
}

生成海报

ps:一般是点击生成海报的时候再调用 getPoster,页面展示直接用 PosterView 组件即可

首先需要再 template 中新增一个 canvas 组件

<canvas canvas-id="posterCanvas" id="posterCanvas" type="2d" />

绘制 canvas 海报

import { getPoster } from "@sh-rep/super-poster";
let json = {
  width: 750, //画布宽度
  height: 1125, //画布高度
  displayWidth: 690, //展示宽度
  ratio: 1.5, // 画笔缩放比
  posterFileName: "poster1",
  doms: [
    {
      type: "text", //dom类型
      x: 0, //x坐标
      y: 56, //y坐标
      width: 750, //文本宽度
      value: "宇宙最强最强的小分队", //文本内容
      fontSize: 48, //字体大小
      color: "#212224", //文本颜色
      fontWeight: "bold", //字重
      lineNum: 1, //行数
      textAlign: "center", //左右对其方式
      borderColor: "#000", //文字描边颜色
      borderWidth: 0, //文字描边宽度
      rotate: 0, //旋转角度
      zIndex: 10,
    },
  ],
};
getPoster(json).then((res) => {
  console.log(res.img);
});

配置

config

参数名类型参数描述默认值是否必传
widthnumber画布宽度-
heightnumber画布高度-
displayWidthnumberdom 展示的宽度-
rationumber画布缩放比1
bgColorstring画布背景色-
posterFileNamestring海报缓存的文件名Date.now()
useCanvasauto、canvas、offscreenCanvas渲染模式'offscreenCanvas'
componentInstanceany若在组件中调用,则需要传入组件实例-
domsArray海报元素列表Doms-

doms

dom 一共有:text、texts、image、block 这几种类型

text

文本

参数名类型参数描述默认值是否必传
typestringdom 类型固定值 text
xnumber起点位置 x 坐标0
ynumber起点位置 y 坐标0
valuestring文本内容-
widthnumber文本区宽度config.width
fontSizenumber文字大小-
colorstring文字颜色-
fontWeightstring | number字重normal
lineNumnumber行数1
textAlignstring对齐方式left
borderColorstring字体边框颜色-
borderWidthnumber字体边框宽度-
rotatenumber旋转角度0
zIndexnumber元素层级0

例:

{
    type: 'text', //dom类型
    x: 0, //x坐标
    y: 56, //y坐标
    width: 750, //文本宽度
    value: '宇宙最强最强的小分队', //文本内容
    fontSize: 48, //字体大小
    color: '#212224', //文本颜色
    fontWeight: 'bold', //字重
    lineNum: 1, //行数
    textAlign: 'center', //左右对其方式
    borderColor: '#000', //文字描边颜色
    borderWidth: 0, //文字描边宽度
    rotate: 0, //旋转角度
    zIndex: 10,
}

texts

多规格文本

参数名类型参数描述默认值是否必传
typestringdom 类型固定值 texts
xnumber起点位置 x 坐标0
ynumber起点位置 y 坐标0
widthnumber文本区宽度config.width
textAlignstring对齐方式left
textsTextsDom文本列表-

TextsDom

参数名类型参数描述默认值是否必传
valuestring文本内容-
fontSizenumber字体大小-
colorstring颜色#000
fontWeightnumber | string字重normal

例:

{
    type: 'texts',
    x: 352, //x坐标
    y: 1025, //y坐标
    width: 317,
    textAlign: 'center',
    texts: [
        {
            value: '-85.5', //文本内容
            fontSize: 48, //字体大小
            color: '#000', //文本颜色
            fontWeight: 'bold', //字重
        },
        {
            value: '斤', //文本内容
            fontSize: 36, //字体大小
            color: '#000', //文本颜色
            fontWeight: 'bold', //字重
        },
    ],
}

image

图片

参数名类型参数描述默认值是否必传
typestringdom 类型固定值 image
urlstring图片路径-
xnumber起点位置 x 坐标0
ynumber起点位置 y 坐标0
widthnumber图片宽度config.width
heightnumber图片高度config.height
borderRadiusnumber图片圆角半径0
borderColorstring图片边框颜色#000
borderWidthnumber图片边框宽度0
rotatenumber旋转角度0
clipnumber图片裁剪的顶点坐标集合 例如[0,0,0,100,100,200,200,0]-
zIndexnumber元素层级0

例:

{
    type: 'image',
    url: 'https://hellosanbao-1257196807.cos.ap-chengdu.myqcloud.com/wangyiyun/WechatIMG12.jpeg',
    x: 0,
    y: 0,
    width: 750,
    height: 1125,
    borderWidth: 6,
    borderColor: '#000',
    clip: [[0,0],[0,100],[200,150],[200,0]],
    zIndex: 2,
},

rect

矩形

参数名类型参数描述默认值是否必传
typestringdom 类型固定值 rect
xnumber起点位置 x 坐标0
ynumber起点位置 y 坐标0
widthnumber宽度-
heightnumber高度-
bgColorstring背景色-
borderRadiusArraynumber圆角-

block

dom 集合块

参数名类型参数描述默认值是否必传
typestringdom 类型固定值 block
xnumber起点位置 x 坐标0
ynumber起点位置 y 坐标0
widthnumber宽度-
heightnumber高度-
rotatenumber旋转角度0
rotateOriginnumberx,y旋转中心店-
translatenumberx,y偏移量-
domsDomsdom 列表-

例:

{
    type: 'block',
    x: 0,
    y: 0,
    width: 750,
    height: 1125,
    rotate:10,
    rotateOrigin: [0,0],
    translate: [0, 0],
    doms: [
       {
            type: 'image',
            url: 'https://hellosanbao-1257196807.cos.ap-chengdu.myqcloud.com/wangyiyun/WechatIMG12.jpeg',
            x: 0,
            y: 0,
            width: 750,
            height: 1125,
            borderWidth: 6,
            borderColor: '#000',
            clip: [[0,0],[0,100],[200,150],[200,0]],
            zIndex: 2,
        },
        {
            type: 'text', //dom类型
            x: 0, //x坐标
            y: 56, //y坐标
            width: 750, //文本宽度
            value: '宇宙最强最强的小分队', //文本内容
            fontSize: 48, //字体大小
            color: '#212224', //文本颜色
            fontWeight: 'bold', //字重
            lineNum: 1, //行数
            textAlign: 'center', //左右对其方式
            borderColor: '#000', //文字描边颜色
            borderWidth: 0, //文字描边宽度
            rotate: 0, //旋转角度
            zIndex: 10,
        }
    ],
}
0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.4

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.3

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.1.0

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.20

1 year ago

0.0.16

2 years ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago