WeChat Mini Programs launched snapshot to generate posters, eliminating the need to draw canvases manually.
CTOnews.com Sept. 14 news, partners who have produced WeChat Mini Programs's poster function know that this function is generally achieved through canvas canvas drawing and server rendering, but they all need to be scripted manually, and it is not very convenient to make them.
In order to meet the needs of Mini Program to generate posters efficiently, Wechat announced the introduction of snapshot components in the Skyline rendering engine to quickly solve complex typesetting, super-long posters and other difficult problems.
According to reports, compared with the existing ways of canvas rendering and server-side rendering, snapshot components have the following advantages:
Easy to deal with complex typesetting, such as rounded corners, percentages, custom fonts and other styles can be easily adjusted
No width and height limit, support the output of super-long posters
The calling method is simple, and it is directly realized by using wxml.
The ▲ snapshot component generates the poster and saves it locally. The source is the official account of "Wechat developer". In addition, the complete process of generating Mini Program poster and saving the local image through the snapshot component is also very simple:
Use wxml to draw poster content
Use the snapshot component to wrap the poster's wxml
Call takeSnapshot to get picture data
Call fs.writeFileSync to write poster data to a local file
Call wx.saveImageToPhotosAlbum to save the poster locally
In other words, users can use wxml to write poster layout like Mini Program UI, and then directly fill in dynamic data, which is much easier to use, and interested CTOnews.com partners can try it in the project.