Home  >  Article  >  WeChat Applet  >  Let’s talk about how to use a small program to generate posters (plug-in recommended)

Let’s talk about how to use a small program to generate posters (plug-in recommended)

青灯夜游
青灯夜游forward
2021-09-13 18:36:173076browse

How to use a small program to generate posters? In this article, I will recommend a poster generation plug-in - painter, and see how to use it to generate posters. I hope it will be helpful to you!

Let’s talk about how to use a small program to generate posters (plug-in recommended)

Mini program native code generation poster

First step:

Download the package and place the painter package in the components directory

 https://github.com/Kujiale-Mobile/Painter

[Related learning recommendations: 小program development tutorial]

Step 2:

Introduced into the json file of the page

{
  "usingComponents": {
    "painter":"/components/painter/painter"
  }
}

Step 3:

Use the wxml of the page

接收海报的图片容器
<image mode="widthFix" src="{{ posterImg }}" id="goods_qr-code" alt />

<painter wx-if="{{showPainter}}" palette="{{data}}" bind:imgOK="firstImg" />
  
palette        字段作为画图数据的数据源, 图案数据以 json 形式存在
widthPixels    强制指定生成的图片的像素宽度

绘图完成后,可以通过绑定 imgOK 或 imgErr 事件来获得成功后的图片或失败的原因

Step 4:

Use the js of the page

生成海报的方法(){
this.setData({
        template: {
          width: "750rpx",
          height: "1500rpx",
          views: [
            {
              type: &#39;image&#39;,
              url: 图片路路径,
              css: {
                top: &#39;10rpx&#39;,
                left: &#39;10rpx&#39;,
                right: &#39;10rpx&#39;,
                width: &#39;730rpx&#39;,
                height: &#39;1500rpx&#39;
              }
            }
          ]
        }
     })
}

  海报生成完毕自动调用
  
  firstImg(e) {
    console.log(e.detail.path);
    this.setData({
      posterImg: e.detail.path
    })
  },

Plug-in introduction and official website: Painter generates posters

https://codechina.csdn.net/mirrors/Kujiale-Mobile/Painter?utm_source=csdn_github_accelerator

Original address: https://juejin.cn/post/6995356720125968398

Author: Huang Yongchao

For more programming-related knowledge, please visit: Programming Video ! !

The above is the detailed content of Let’s talk about how to use a small program to generate posters (plug-in recommended). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:掘金--黄勇超. If there is any infringement, please contact admin@php.cn delete