微信小程序:一个json帮你在朋友圈分享图片

网友投稿 188 2024-06-10

Written in front

微信小程序:一个json帮你在朋友圈分享图片

I have been working on a small program recently and found that making pictures to share in Moments is a must for every project. There were a lot of pitfalls and it was tedious to write, and I couldn’t find a similar component, so I wrote one myself.

Demo

The left side is drawn by canvasdrawer , and the right side is the picture given by UI

Features

Easy to use - just one json to draw pictures

Full-featured——meet 90% of usage scenarios

Draw text (line breaks, ellipses beyond content, underline, underline, bold text)

Draw the picture

Draw the rectangle

##Save the pictureMulti-picture drawing...Small amount of code

Experience

1

git clone https://github.com/kuckboy1994/mp_canvas_drawer

Copy after login
If you want to use it on your mobile phone, just configure your own appid. Two commonly used modes have been configured for you in the compilation mode: Normal drawing and drawing a single sharing picture. Multiple drawings, continuous drawing of shared drawings

Use

git clone https://github.com/kuckboy1994/mp_canvas_drawer to the local

put the

in components canvasdrawer Copy to your own project.

Register the component using the page

1

2

3

4

5

{

  "usingComponents": {

    "canvasdrawer": "/components/canvasdrawer/canvasdrawer"

  }

}

Copy after login
Add the following code to the page **.wxml file

1

<canvasdrawer painting="{{painting}}" bind:getimage="eventGetImage"></canvasdrawer>

Copy after login
           

painting   is the json that needs to be passed in. The getImage method is a callback function after the drawing is completed, and returns the completed image address in event.detail .

The painting in the current chestnut is briefly displayed. For detailed configuration, please see

API

##APIThe first layer of the data object requires three parameters: width

, height, views. All numbers in the configuration are unitless. This means that canvas draws a proportional diagram. To determine the specific display size, simply place the returned image path in the image tag. Currently, 3 types of configurations can be drawn:

image

, text, rect. The configured attributes basically use camel case names of css, which are relatively easy to understand.

image

##topThe distance between the upper left corner and the top of the artboard# #left##widthHow wide to draw0How high to drawAttributeMeaningDefault value

Optional valueurlThe drawn image address can be a local image, such as: /images/1.jpeg

The distance between the upper left corner and the left side of the artboard

##height0

text(text)

##AttributeMeaningDefault valueOptional valuecontentThe drawn image address''(empty string )colorcolorblackfontSizeFont size16##textAlignlineHeight

rect (rectangle, line)

Text alignmentleftcenter,rightLine height, only in multi-line text Useful20

##AttributeMeaningDefault valueOptional valuebackgroundBackground colorblack##top##leftThe distance between the upper left corner and the left side of the artboard16widthHow wide to draw0heightHow high to draw0

The distance between the upper left corner and the top of the artboard

##

Q&A

最佳实践

绘制操作的时候最好 锁住屏幕 ,例如在点击绘制的时候

1

wx.showLoading({  title: '绘制分享图片中',  mask: true})

Copy after login

绘制完成之后

1

wx.hideLoading()

Copy after login

具体可以参考项目下的 /pages/multiple

1.二维码和小程序码如何绘制?

   二维码和小程序码可以通过调用微信官方的接口产生,需要后端配合。

  然后走 type: image 类型进行绘制即可。

2.绘制流程相关

  views 数组中的顺序代表绘画的先后顺序,会有覆盖的现象。请各位使用者注意。

3.如何实现圆形头像?

   canvas 中没有绘制圆形图片的方法,所以使用了 hack 的方式来实现的。使用一张中间镂空的图片盖在头像上就可实现当前效果。

4.canvas drawer 组件为什么不直接显示canvas画板和其内容呢?

    考虑到大部分场景,我们都是用来把图片保存到本地,或用以展示。保存到本地,返回临时文件给调用者一定是最佳的解决方式。展示,转化成图片之后,就可以使用 image 基础组件的所有显示模式了,还能设置宽高。

推荐教程:《微信小程序

The above is the detailed content of WeChat Mini Program: A json helps you share pictures in your circle of friends. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
WeChat applet
source:juejin-
Previous article:Summary of knowledge points on WeChat mini programs Next article:Can you use vue to write small programs?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php-
Latest articles by author
What impact will robots have on the future?
2020-07-04 16:03:41
What does it mean that the office copy has not been activated yet?
2020-07-04 15:58:55
What does import java.util.* mean?
2020-07-04 15:52:16
What are the four ways to create a thread pool in java
2020-07-04 15:44:43
What are the cloud computing aspects in life?
2020-07-04 15:39:55
Detailed explanation of the usage of conditional function if
2020-07-04 15:25:58
Check what java version is
2020-07-04 15:10:08
What are the six basic statements in C language?
2020-07-04 15:04:01
What software to use to learn C language
2020-07-04 14:56:00
What is the system() function?
2020-07-04 14:51:44
Latest issues
function_exists() cannot determine the custom function Function test () {return true;} if (function_exists ('test')) {echo "test is function...
From 2024-04-29 11:01:01
0 1 362
How to display the mobile version of Google Chrome Hello teacher, how can I change Google Chrome into a mobile version?
From 2024-04-23 00:22:19
0 6 453
The child window operates the parent window, but the output does not respond. The first two sentences are executable, but the last sentence cannot be implemented.
From 2024-04-19 15:37:47
0 1 453
There is no output in the parent window document.onclick = function(){ window.opener.document.write('I am the output of the child ...
From 2024-04-18 23:52:34
0 0 314
Where is the courseware about CSS mind mapping? Courseware
From 2024-04-16 10:10:18
0 0 406
PX automatic conversion to REM error  <style>html {   font-size: calc(100vw / 3.75);      }...
From 2024-04-16 09:34:16
0 0 3994
PHP arrays obtained from URL parameters do not behave as expected I have a URL parameter that contains the category ID and I want to treat it as an array li...
From 2024-04-06 22:09:02
0 1 725
Move the content to the left by adding the Width property I have provided margins to the body. main {left margin: 200px; right margin: 200px; text a...

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微信小程序首页打不开的解决办法
下一篇:微信引用功能的含义阐释
相关文章

 发表评论

暂时没有评论,来抢沙发吧~