0.0.2 • Published 3 years ago

miniprogram-canvas-to-img v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

canvas-to-image

小程序内通过传入背景图和二维码参数,生成朋友圈分享海报

使用方法

Step1. npm 安装,参考 小程序 npm 支持

npm install --save miniprogram-canvas-to-img

Step2. JSON 组件声明

{
  "usingComponents": {
    "canvas-to-image": "miniprogram-canvas-to-img",
  }
}

Step3. wxml 引入组件

  <canvas-to-image 
    width="{{width}}"
    height="{{height}}"
    shareText="{{shareText}}"
    bgImage="{{bgImage}}" 
    shareText="{{shareText}}" 
    qrCode="{{qrCode}}"
    bindbeforecreate="beforecreate"
    bindbeforesave="beforesave" 
    bindsaved="saved"
    binderror="showError"
    id="savaCanvas"
    show="{{true}}" 
>
</canvas-to-image>

属性列表

属性类型默认值必填说明
widthNumber海报宽度
heightNumber海报高度
bgImageString背景图地址
qrCodeObject二维码配置对象
shareTextArray分享文案配置对象数组
shareImageArray扩展分享图配置对象数组

shareText item属性列表

属性类型默认值必填说明
valueString文案
xNumber相对背景图X坐标
yNumber相对背景图的Y坐标
colorStringblack颜色
fontSizeNumber16字体大小
boldBooleanfalse是否加粗
textAlignStringleft文本水平对齐方式
verticalAlignStringnormal垂直对齐方式
maxWidthNumber750最大宽度(超过换行)
lineHeightNumber1行高

qrCode / shareImage(item) 属性列表

属性类型默认值必填说明
urlString二维码图片地址
xNumber相对背景图的X坐标
yString相对背景图的Y坐标
widthNumber140图片宽度
heightNumber140图片高度

方法

保存海报到相册

wxml:

<canvas-to-image 
    width="{{width}}"
    height="{{height}}"
    shareText="{{shareText}}"
    bgImage="{{bgImage}}" 
    shareText="{{shareText}}" 
    qrCode="{{qrCode}}"
    bindbeforecreate="beforecreate"
    bindbeforesave="beforesave" 
    bindsaved="saved"
    binderror="showError"
    id="savaCanvas"
    show="{{true}}" 
>
</canvas-to-image>
<button bindtap="save">保存到手机</button>


js:

save() {
  this.selectComponent('#savaCanvas').saveImage();
}