WeChat Mini Program: A json helps you share pictures in your circle of friends
hzc
Release: 2020-06-12 10:01:36
forward
3508 people have browsed it
Written in front
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
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.
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
##API
The 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
Attribute
Meaning
Default value
Optional value
url
The drawn image address can be a local image, such as: /images/1.jpeg
##top
The distance between the upper left corner and the top of the artboard
# #left
The distance between the upper left corner and the left side of the artboard
##width
How wide to draw
0
##height
How high to draw
0
text(text)
##Attribute
Meaning
Default value
Optional value
content
The drawn image address
''(empty string )
color
color
black
fontSize
Font size
16
##textAlign
Text alignment
left
center,right
lineHeight
Line height, only in multi-line text Useful
20
rect (rectangle, line)
##Attribute
Meaning
Default value
Optional value
background
Background color
black
##top
The distance between the upper left corner and the top of the artboard
##left
The distance between the upper left corner and the left side of the artboard
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!
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.cn