Home Web Front-end JS Tutorial Implementation of the function of saving pictures and sharing them in the circle of friends in the mini program

Implementation of the function of saving pictures and sharing them in the circle of friends in the mini program

May 25, 2018 am 10:25 AM
share Applets friend

This time I will bring you the implementation of the mini program's function of saving pictures and sharing them in Moments. What are the precautions for implementing the mini program's function of saving pictures and sharing them in Moments? The following is a practical case, let's take a look.

Explanation

First of all, please note that you cannot share directly to Moments within the mini program. Therefore, we can only generate pictures, carry the QR code of the mini program, save them to the mobile phone album, and let users choose to send them to their circle of friends. Then you can enter the designated page of the mini program by identifying the QR code in the mini program. Referring to the applications on the market that support sharing, they are basically implemented in this way.

Preparation stage

1. Obtain the mini program code through the server

You can refer to it here WeChat's official documentation specifies parameters, paths and other information for the backend, allowing the backend to generate the specified mini program code. Then call wx.getImageInfo to save the small program code generated in the background.

Note that you must read the WeChat documentation carefully. If the path to generate the mini program code on the official server does not exist, the generation will fail. This is also very annoying and very inconvenient Debugging.

wx.getImageInfo({            
  src:'https://xxx.jpg',//服务器返回的带参数的小程序码地址
  success: function (res) {
    //res.path是网络图片的本地地址
    qrCodePath = res.path;
  },
  fail: function (res) {
    //失败回调
  }
});
Copy after login

1. Draw the required information through canvas

After preparing all the pictures, you can draw them through canvas, and then export the canvas as a picture. Regarding drawing, you can refer to WeChat's canvas API. The following are basically based on the API methods.

There are several points that need to be noted.

1. I don’t know the length of the drawn text, so I don’t know when the text should wrap. Therefore, for the product title, the multi-line data may be fixed to 18 characters per line.

2. It is about the export of drawing pictures. According to the official API, it should be executed in the callback of draw() completion, but in this way, the callback is never completed. Don't know what went wrong. So in the end I had to add a delay to save the picture.

canvasCtx.draw(false,function(res){
});
Copy after login

Finally, take a look at the renderings.

# I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Using front-end methods to convert images into character paintings


Detailed explanation of the steps to use JS array method

The above is the detailed content of Implementation of the function of saving pictures and sharing them in the circle of friends in the mini program. For more information, please follow other related articles on the PHP Chinese website!

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.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to share Quark Netdisk to Baidu Netdisk? How to share Quark Netdisk to Baidu Netdisk? Mar 14, 2024 pm 04:40 PM

Quark Netdisk and Baidu Netdisk are very convenient storage tools. Many users are asking whether these two softwares are interoperable? How to share Quark Netdisk to Baidu Netdisk? Let this site introduce to users in detail how to save Quark network disk files to Baidu network disk. How to save files from Quark Network Disk to Baidu Network Disk Method 1. If you want to know how to transfer files from Quark Network Disk to Baidu Network Disk, first download the files that need to be saved on Quark Network Disk, and then open the Baidu Network Disk client. , select the folder where the compressed file is to be saved, and double-click to open the folder. 2. After opening the folder, click "Upload" in the upper left corner of the window. 3. Find the compressed file that needs to be uploaded on your computer and click to select it.

How to share NetEase Cloud Music to WeChat Moments_Tutorial on sharing NetEase Cloud Music to WeChat Moments How to share NetEase Cloud Music to WeChat Moments_Tutorial on sharing NetEase Cloud Music to WeChat Moments Mar 25, 2024 am 11:41 AM

1. First, we enter NetEase Cloud Music, and then click on the software homepage interface to enter the song playback interface. 2. Then in the song playback interface, find the sharing function button in the upper right corner, as shown in the red box in the figure below, click to select the sharing channel; in the sharing channel, click the "Share to" option at the bottom, and then select the first "WeChat Moments" allows you to share content to WeChat Moments.

How to share files with friends on Baidu Netdisk How to share files with friends on Baidu Netdisk Mar 25, 2024 pm 06:52 PM

Recently, Baidu Netdisk Android client has ushered in a new version 8.0.0. This version not only brings many changes, but also adds many practical functions. Among them, the most eye-catching is the enhancement of the folder sharing function. Now, users can easily invite friends to join and share important files in work and life, achieving more convenient collaboration and sharing. So how do you share the files you need to share with your friends? Below, the editor of this site will give you a detailed introduction. I hope it can help you! 1) Open Baidu Cloud APP, first click to select the relevant folder on the homepage, and then click the [...] icon in the upper right corner of the interface; (as shown below) 2) Then click [+] in the "Shared Members" column 】, and finally check all

What is the difference between TikTok fans and friends? How to increase fans? What is the difference between TikTok fans and friends? How to increase fans? Mar 07, 2024 pm 09:52 PM

As one of the most popular short video platforms in China, Douyin has attracted a large number of users and fans. On TikTok, we often hear about fans and friends, but do you know what the difference is between TikTok fans and friends? This question will be answered in detail below. 1. What is the difference between Douyin fans and friends? On TikTok, fans are people who are interested in your content and choose to follow you. They will interact with you through likes, comments, etc. to establish a virtual connection. Friends, on the other hand, are people who know each other in real life and have real social relationships with each other. On social platforms like Douyin, the methods and depth of interactions between fans and friends may vary, but they are all important elements in building and maintaining a social network. The number of fans refers to those who follow your account

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

Mango tv member account sharing 2023 Mango tv member account sharing 2023 Feb 07, 2024 pm 02:27 PM

Mango TV has various types of movies, TV series, variety shows and other resources, and users can freely choose to watch them. Mango TV members can not only watch all VIP dramas, but also set the highest definition picture quality to help users watch dramas happily. Below, the editor will bring you some free Mango TV membership accounts for users to use, hurry up and take a look Take a look. Mango TV latest member account free sharing 2023: Note: These are the latest member accounts collected, you can log in directly and use them, do not change the password at will. Account number: 13842025699 Password: qds373 Account number: 15804882888 Password: evr6982 Account number: 13330925667 Password: jgqae Account number: 1703

What are the activation keys for win7 enterprise edition? What are the activation keys for win7 enterprise edition? Jul 09, 2023 pm 03:01 PM

Do you have the latest activation key for win7 enterprise edition? If you install the official win7 enterprise version, you will be prompted to activate it with the windows7 enterprise product key, otherwise it will not work properly. So the editor will share with you some win7 enterprise version activation passwords, let's take a look. Q3VMJ-TMJ3M-99RF9-CVPJ3-Q7VF3KGMPT-GQ6XF-DM3VM-HW6PR-DX9G8MT39G-9HYXX-J3V3Q-RPXJB-RQ6D79JBBV-7Q7P7-CTDB7-KYBKG-X8HHCP72QK-2Y3B8-YDHDV-29DQB-QKWWM6 JQ

How uniapp achieves rapid conversion between mini programs and H5 How uniapp achieves rapid conversion between mini programs and H5 Oct 20, 2023 pm 02:12 PM

How uniapp can achieve rapid conversion between mini programs and H5 requires specific code examples. In recent years, with the development of the mobile Internet and the popularity of smartphones, mini programs and H5 have become indispensable application forms. As a cross-platform development framework, uniapp can quickly realize the conversion between small programs and H5 based on a set of codes, greatly improving development efficiency. This article will introduce how uniapp can achieve rapid conversion between mini programs and H5, and give specific code examples. 1. Introduction to uniapp unia

See all articles