关于微信小程序生成海报一个简单的办法

news/2024/7/20 0:59:23 标签: 微信小程序, 小程序

废话不多说,直接入题,先上GITHUB地址,这个组件很好用,有图形生成工具,你不用再自己写代码一个个元素对齐了,是不是很爽。

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

生成painter代码:React App 这个很好用吧,自己把设计变成海报,然后复制出代码

充分利用painter的优势。小程序生成图片库,轻松通过 json 方式绘制一张可以发到朋友圈的图片>>Painter

这个也简单,先下载源代码,然后小程序根目录里建一个components文件夹,把程序代码贴进去,当然你可以用GIT命令,省去手动下载的麻烦。

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

新建一个生成海报的小程序页面,引入这个组件

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

生成海报代码:

<painter customStyle='position: absolute; left: -9999rpx;' palette="{{template}}" bind:imgOK="onImgOK" widthPixels="1000"/>

数据传入后,则会自动进行绘图。绘图完成后,你可以通过绑定 imgOK 或 imgErr 事件来获得成功后的图片 或失败的原因。

bind:imgOK="onImgOK"
bind:imgErr="onImgErr"

onImgOK(e) {
  其中 e.detail.path 为生成的图片路径
},

第一步生成的海报代码可以放进页面,然后修改图片地址为动态的即可。


palette() {
        return (
{
  "width": "654px",
  "height": "1000px",
  "background": "#FEF8F3",
  "views": [
    {
      "type": "qrcode",
      "content": "哈哈哈",
      "css": {
        "color": "#000000",
        "background": "#ffffff",
        "width": "200px",
        "height": "200px",
        "top": "779px",
        "left": "29px",
        "rotate": "0",
        "borderRadius": "10px"
      }
    },
    {
      "type": "text",
      "text": "扫码关注",
      "css": {
        "color": "#ff0000",
        "background": "rgba(0,0,0,0)",
        "width": "200px",
        "height": "43.89999999999999px",
        "top": "2px",
        "left": "1113px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "1px",
        "borderColor": "#000000",
        "shadow": "10 10 5 #888888",
        "padding": "0px",
        "fontSize": "30px",
        "fontWeight": "normal",
        "maxLines": "2",
        "lineHeight": "43.290000000000006px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "",
        "textAlign": "left"
      }
    },
    {
      "type": "text",
      "text": "扫码关注",
      "css": {
        "color": "#ff0000",
        "background": "rgba(0,0,0,0)",
        "width": "200px",
        "height": "43.89999999999999px",
        "top": "2px",
        "left": "1113px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "1px",
        "borderColor": "#000000",
        "shadow": "10 10 5 #888888",
        "padding": "0px",
        "fontSize": "30px",
        "fontWeight": "normal",
        "maxLines": "2",
        "lineHeight": "43.290000000000006px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "",
        "textAlign": "left"
      }
    },
    {
      "type": "text",
      "text": "扫码关注",
      "css": {
        "color": "#C87756",
        "background": "rgba(0,0,0,0)",
        "width": "30px",
        "height": "175.10999999999996px",
        "top": "787.94px",
        "left": "254px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#000000",
        "shadow": "",
        "padding": "0px",
        "fontSize": "30px",
        "fontWeight": "normal",
        "maxLines": "5",
        "lineHeight": "43.290000000000006px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "",
        "textAlign": "left"
      }
    },
    {
      "type": "text",
      "text": "1. 忌食辛辣刺激食物\n2. 忌运动量过大\n3. 戒烟戒酒,忌暴饮暴食",
      "css": {
        "color": "#C87756",
        "background": "rgba(0,0,0,0)",
        "width": "250px",
        "height": "93.88px",
        "top": "611px",
        "left": "40px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#000000",
        "shadow": "",
        "padding": "0px",
        "fontSize": "20px",
        "fontWeight": "normal",
        "maxLines": "6",
        "lineHeight": "31.080000000000002px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "",
        "textAlign": "left"
      }
    },
    {
      "type": "text",
      "text": "养生小贴士",
      "css": {
        "color": "#C87756",
        "background": "rgba(0,0,0,0)",
        "width": "200px",
        "height": "42.89999999999999px",
        "top": "537px",
        "left": "42px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#C87756",
        "shadow": "",
        "padding": "0px",
        "fontSize": "30px",
        "fontWeight": "bold",
        "maxLines": "2",
        "lineHeight": "43.290000000000006px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "webfontzk",
        "textAlign": "left"
      }
    },
    {
      "type": "text",
      "text": "分",
      "css": {
        "color": "#C87756",
        "background": "rgba(0,0,0,0)",
        "width": "130px",
        "height": "185.89999999999998px",
        "top": "708px",
        "left": "484px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#000000",
        "shadow": "",
        "padding": "0px",
        "fontSize": "130px",
        "fontWeight": "normal",
        "maxLines": "2",
        "lineHeight": "187.59000000000003px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "webfontzkxw",
        "textAlign": "left"
      }
    },
    {
      "type": "text",
      "text": "秋",
      "css": {
        "color": "#C87756",
        "background": "rgba(0,0,0,0)",
        "width": "130px",
        "height": "185.89999999999998px",
        "top": "580px",
        "left": "463.5px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#000000",
        "shadow": "",
        "padding": "0px",
        "fontSize": "130px",
        "fontWeight": "normal",
        "maxLines": "2",
        "lineHeight": "187.59000000000003px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "webfontzkxw",
        "textAlign": "left"
      }
    },
    {
      "type": "image",
      "url": "https://static.fotor.com.cn/assets/res/pic/454d3884-b1d1-4059-a08b-18427f93c8eb.jpg?x-oss-process=image/resize,lfit,h_1200,w_1200/format,src",
      "css": {
        "width": "568.01px",
        "height": "475.27px",
        "top": "0px",
        "left": "39.19px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#000000",
        "shadow": "",
        "mode": "scaleToFill"
      }
    },
    {
      "type": "text",
      "text": "请朋友们注意防寒保暖,小心着凉",
      "css": {
        "color": "#fff",
        "background": "rgba(0,0,0,0)",
        "width": "22px",
        "height": "372.9000000000001px",
        "top": "61px",
        "left": "71px",
        "rotate": "0",
        "borderRadius": "",
        "borderWidth": "",
        "borderColor": "#000000",
        "shadow": "",
        "padding": "0px",
        "fontSize": "22px",
        "fontWeight": "normal",
        "maxLines": "22",
        "lineHeight": "24.42px",
        "textStyle": "fill",
        "textDecoration": "none",
        "fontFamily": "",
        "textAlign": "left"
      }
    }
  ]
}
        );
      }

关于如何生成小程序码,请看小程序文档,写的很清楚了,先获取TOKEN然后调用接口即可生成,把图片保存服务器生成小程序码的URL

文档地址:获取不限制的小程序码 | 微信开放文档

另外,生成的海报如果保存一键转发,小程序文档也有相应的接口,直接可以使用,不过请注意你开发工具的版本要高于2.16.0

地址也发下吧:wx.showShareImageMenu(Object object) | 微信开放文档

 

至此,完成了小程序生成海报分享功能。 


http://www.niftyadmin.cn/n/452789.html

相关文章

虚拟机网卡/网络配置,静态IP配置

文章目录 1. Vmvare设置 “编辑->虚拟机网络编辑”2. 新建一个虚拟机并给它设置网卡3. 配置eth0网卡为静态IP vim /etc/sysconfig/network-scripts/ifcfg-eth04、测试 1. Vmvare设置 “编辑->虚拟机网络编辑” 这里设置了3个虚拟网络(两个主机模式&#xff0c;这两个网络…

Linux使用NDK编译libtiff库并移植到Android平台

1.系统要求: ubuntu 20.04 LTS桌面版本 2.下载libtiff源码: 打开libtiff官方网站 ,打开libtiff源码仓库 http://www.simplesystems.org/libtiff/ 复制下载仓库地址: 克隆源码到本址: git clone --recursive https://gitlab.com/libtiff/libtiff.git 进入源码目录 3.安装…

Linux下MySQL 数据库,数据表使用

今天学习在数据库中创建数据表和插入数据 创建数据库&#xff1a;create database 库名 创建数据表&#xff1a;create table 表名 字段 插入数据 &#xff1a; INSERT INTO 数据表名 里面 name 是字符串类型的字段 VALUES是一个关键字&#xff0c;用于在IN…

matlab矩阵测试、大小、类型函数

测试函数 函数名称说明isempty( A)检测矩阵是否为空isscalar( A)检测矩阵是否是单元素的标量知阵isvector( A)检测矩阵是否是只具有一行或一列元素的一维向量issparse( A)检测数组是否是稀疏矩阵 >> aones(4)a 1 1 1 11 1 1 11 1 1 …

vue面试题1. 请说下封装 vue 组件的过程?2. Vue组件如何进行传值的?3. Vue 组件 data 为什么必须是函数?4. 讲一下组件的命名规范

1. 请说下封装 vue 组件的过程&#xff1f; 首先&#xff0c;组件可以提升整个项目的开发效率。能够把页面抽象成多个相对独立的模块&#xff0c;解决了我们传统项目开发&#xff1a;效率低、难维护、复用性等问题。 分析需求&#xff1a;确定业务需求&#xff0c;把页面中可以…

常见web中间件漏洞复现总结

文章目录 IISPUT漏洞iis6.0 解析漏洞IIS短文件漏洞远程代码执行(RCE-CVE-2017-7269)iis7.x文件解析漏洞HTTP.SYS远程代码执行 (MS15-034) apache未知扩展名解析漏洞AddHandler解析漏洞目录遍历漏洞Apache HTTPD 换行解析漏洞&#xff08;CVE-2017-15715&#xff09; Nginx文件解…

spring-security -oauth2 整合 JWT

前言 在这个基础上&#xff0c;进行整合。 spring security oauth2学习 -- 快速入门_本郡主是喵的博客-CSDN博客 1.jwt的一般使用 先把 reids,common-pools 等依赖删掉。 删掉redis的下相关配置 1.1 导入依赖 <!--jjwt--><dependency><groupId>io.json…

5.3.4 因特网的路由协议(四)BGP协议

5.3.4 因特网的路由协议&#xff08;四&#xff09;BGP协议 我们学习的RIP协议&#xff08;5.3.2 因特网的路由协议&#xff08;二&#xff09;基于距离向量算法的RIP协议&#xff09;和OSPF协议&#xff08;5.3.3 因特网的路由协议&#xff08;三&#xff09;OSPF协议&#x…