之前在写海报的时候自己也封装过一个,这里再给大家推荐一个组件wxa-plugin-canvas。目前就使用感来说还是不错的。这里有一个开源的地址,大家可以把它下载下来放进自己的组件中
开源项目地址:https://github.com/jasondu/wxa-plugin-canvas
开源项目作者:jason
使用注意事项
- 图片的域名务必添加到downloadFile合法域名中(开发设置-服务器域名-downloadFile合法域名)
- 如果要使用异步生成海报的方法,务必组件要加上
id="poster"
使用方法
在需要的界面引入:
{
"enablePullDownRefresh": true,
"usingComponents": {
"poster": "/components/wxa-plugin-canvas/poster/index",
}
}
在wxml界面添加一个下载的按钮
<poster id="poster" config="{
{posterConfig}}" bind:success="onPosterSuccess" bind:fail="onPosterFail">
<view >下载海报</view>
</poster>
在js中添加海报生成时的配置:posterConfig
var posterConfig = {
width: 648,
height: 886,
backgroundColor: 'rgba(255,255,255,1)',
borderRadius:0,
debug: false,
pixelRatio: 1,
texts: [
{
x:136,
y: 81,
text: '友谊的小船急需你的助力',
fontSize: 30,
fontWeight: '400',
color: '#333',
}
],
images: [
{
width: 80,
height: 80,