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!
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: 'image', url: 图片路路径, css: { top: '10rpx', left: '10rpx', right: '10rpx', width: '730rpx', height: '1500rpx' } } ] } }) } 海报生成完毕自动调用 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!