Image generation method and related equipment

By parsing and converting image data into bitmap images and compressing the format on the server side, the problems of high runtime overhead and long response time during image generation are solved, and fast image loading is achieved.

CN121099080APending Publication Date: 2025-12-09GUANGZHOU HUANJUMARK NETWORK INFORMATION CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511303904.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-11
Publication Date
2025-12-09

AI Technical Summary

Technical Problem

Existing technologies incur high overhead and long response times when generating images in real time, which affects user experience.

Method used

The server-side image generation method receives client requests, parses the image data into a preset format, converts it into a bitmap image using a rendering engine, and then compresses and converts the image before returning it to the client.

Benefits of technology

This reduces the bandwidth required for target image transmission, improving client loading speed and response efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121099080A_ABST
    Figure CN121099080A_ABST
Patent Text Reader

Abstract

The invention relates to an image generation method and related equipment. The method is applied to the server. The server receives an image generation request sent by a client, and analyzes first image data of the image generation request into second image data in a preset format; converting the second image data into a bitmap image by using a preset rendering engine; performing compression and format conversion on the bitmap image to obtain a target image; and returning the target image to the client. The technical problems of high operation overhead and long response time when the client generates the image can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, specifically to an image generation method and related equipment. Background Technology

[0002] Images are increasingly used in modern web pages and applications. High-quality image display can significantly enhance user experience, but it also brings problems such as slow loading speeds and high bandwidth consumption. Furthermore, to improve the user experience, real-time image generation is necessary. However, current technologies for real-time image generation are not only computationally expensive but also have long response times. Summary of the Invention

[0003] In view of the above, it is necessary to provide an image generation method and related equipment to solve the technical problems of high operating overhead and long response time when generating existing images.

[0004] In a first aspect, this application provides an image generation method applied in a server. The method includes: receiving an image generation request sent by a client, and parsing first image data of the image generation request into second image data in a preset format; converting the second image data into a bitmap image using a preset rendering engine; compressing and format-converting the bitmap image to obtain a target image; and returning the target image to the client.

[0005] In some embodiments of this application, receiving an image generation request sent by a client and parsing the first image data of the image generation request into second image data in a preset format includes: the server's load balancer receiving the image generation request sent by the client and sending the image generation request to the application programming interface (API) gateway instance of the server's gateway layer; after the image generation request is verified, the API gateway instance sending the image generation request to the corresponding service instance in the application service layer of the server; and the service instance parsing the first image data into the second image data.

[0006] In some embodiments of this application, verifying the image generation request includes: obtaining a first key from the request header of the image generation request; comparing the first key with a stored second key to authenticate the image generation request; if the first key matches the second key, determining that the authentication of the image generation request is successful; if the first key does not match the second key, determining that the authentication of the image generation request is unsuccessful.

[0007] In some embodiments of this application, the service instance parses the first image data into the second image data by: obtaining object representation JSON image data from the image generation request, filling the JSON image data into placeholders in an HTML template file to obtain HTML image data, or filling the JSON image data into placeholders in a Scalable Vector Graphics (SVG) template file to obtain SVG image data.

[0008] In some embodiments of this application, the method further includes: detecting whether the required fields in the second image data have been filled in; detecting whether the field format and field type in the second image data conform to business rules; if the required fields have been filled in and the field format and field type conform to business rules, determining that the second image data has passed data verification.

[0009] In some embodiments of this application, the method further includes: after the second image data passes data verification, the service instance searches the Redis cache of a remote dictionary server according to the configuration parameters in the second image data to determine whether there is an image in the Redis cache that matches the configuration parameters; if there is an image in the Redis cache that matches the configuration parameters, the service instance uses the image stored in the Redis cache that matches the configuration parameters as the target image and returns the target image to the client; if there is no image in the Redis cache that matches the configuration parameters, the service instance uses the preset rendering engine to convert the second image data into the bitmap image.

[0010] In some embodiments of this application, the service instance uses the preset rendering engine to convert the second image data into the bitmap image, including: loading Chinese font resources; defining the structure and style of the image using a JSX object to obtain JSX elements based on the second image data, optimizing the JSX elements using the preset rendering engine, and converting them into a layout model based on Flexbox; determining an SVG string based on the preset rendering engine, the Chinese font resources, and the layout model; converting the SVG string into a bitmap image using the Sharp image processing library, and compressing and format-converting the bitmap image to obtain the target image.

[0011] In some embodiments of this application, compressing the bitmap image includes: compressing the bitmap image using a preset compression algorithm and parameters of the Sharp image processing library.

[0012] Secondly, this application provides an electronic device, which includes a memory and a processor: the memory is used to store program instructions; the processor is used to read and execute the program instructions stored in the memory, and when the program instructions are executed by the processor, the electronic device performs the above-described image generation method.

[0013] Thirdly, this application provides a computer storage medium storing program instructions that, when executed on an electronic device, cause the electronic device to perform the above-described image generation method.

[0014] In this embodiment, the server returns the target image generated in real time to the client. Since the target image has been compressed and converted, this application can reduce the bandwidth required for target image transmission, and the client can quickly load the target image, thus solving the technical problem of high operating overhead and long response time when the client generates images. Attached Figure Description

[0015] Figure 1 This is an application environment diagram of an image generation system provided in some embodiments of this application.

[0016] Figure 2 A flowchart illustrating an image generation method provided in some embodiments of this application.

[0017] Figure 3 This is a flowchart illustrating an image generation method provided in some other embodiments of this application.

[0018] Figure 4 This is a flowchart illustrating a method for converting second image data into a bitmap image, provided for some embodiments of this application.

[0019] Figure 5 The diagram shows the structure of an electronic device provided in some embodiments of this application. Detailed Implementation

[0020] To better understand the above-mentioned objectives, features and advantages of this application, the application will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0021] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein in the specification of this application is for the purpose of describing an embodiment in one instance only and is not intended to be limiting of the application.

[0022] It should be noted that the terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and drawings of this application are used to distinguish similar objects, and not to describe a specific order or sequence. In the embodiments of this application, the words "exemplary" or "for example" are used to indicate that something is being described as an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.

[0023] It should also be noted that the methods disclosed in the embodiments of this application or the methods shown in the flowcharts include one or more steps for implementing the method. Without departing from the scope of the claims, the execution order of multiple steps can be interchanged, and some steps can be deleted. Some embodiments will be described below with reference to the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0024] Images are increasingly used in modern web pages and applications. High-quality image display can significantly enhance user experience, but it also brings problems such as slow loading speeds and high bandwidth consumption. Furthermore, to improve the user experience, real-time image generation is necessary. However, current technologies for real-time image generation are not only computationally expensive but also have long response times.

[0025] To address the aforementioned technical problems, this application provides an image generation method. This image generation method is applied in an image generation system. (Reference) Figure 1 The diagram illustrates an application environment for an image generation system provided in some embodiments of this application. The image generation system 100 includes a client 10 and a server 20. The client 10 is communicatively connected to the server 20. In some embodiments of this application, the client 10 accesses the Internet via a network interface card or a wireless module and communicates with the server 20. The wireless module can be a 4G / 5G communication module or a Wi-Fi module. In some embodiments of this application, the client includes a web front-end, a mobile application (App) (iOS / Android), a mini-program, or a third-party APP.

[0026] In some embodiments of this application, server 20 includes a load balancer layer 201, a gateway layer 202, an application service layer 203, a file storage layer 204, a data storage layer 205, a cache layer 206, and a monitoring layer 207. Load balancer layer 201 includes a load balancer. In some embodiments of this application, the load balancer can be an Nginx load balancer. The load balancer is used to receive an image generation request sent by client 10 and send the image generation request to the application programming interface (API) gateway instance of gateway layer 202, wherein the image generation request includes image data, such as receipt image data. The API gateway instance sends the image generation request to application service layer 203. In some embodiments of this application, application service layer 203 includes at least one service instance. In some embodiments of this application, a service instance represents an independent process or container of an application service program that is started and running. The service instance is used to obtain corresponding file data from cache layer 206, data storage layer 205, or file storage layer 204 according to the image generation request, process the image data based on the file data, generate a target image, and return the target image to client 10. The data storage layer 205 is used to store the image processing results. The monitoring layer 207 is used to collect performance metrics from each layer, trace request paths, record logs, and issue alarms when performance metrics are abnormal.

[0027] In some embodiments of this application, the client 10 can be a personal computer, laptop, tablet, or smartphone. In some embodiments of this application, the server 20 has an 8-core CPU, 32GB of memory, a solid-state drive (SSD) storage device, and supports Docker containerized deployment. In some embodiments of this application, the server 20 includes a Node.js runtime environment, which represents a JavaScript runtime environment based on the Chrome V8 engine, allowing JavaScript code to be executed on the server side.

[0028] In some embodiments of this application, the image generation system 100 can be deployed in an e-commerce platform. An exemplary e-commerce platform, leveraging internet infrastructure, provides supply and demand matching for products and / or services to the general public. In this e-commerce platform, products and / or services are provided as commodity information. For simplicity, this application uses concepts such as "commodity" and "product" to refer to products and / or services in the e-commerce platform, which can specifically include physical products, digital products, tickets, service subscriptions, and other offline services.

[0029] In reality, various entities can access e-commerce platforms as users, utilizing the various online services provided to participate in the business activities facilitated by the platform. These entities can be natural persons, legal persons, or social organizations. Corresponding to the two types of entities in business activities—merchants and consumers—e-commerce platforms correspondingly have two main categories of users: merchant users and consumer users. All entities in the product distribution chain of business activities, including manufacturers, sellers, retailers, and logistics providers, can use online services on the e-commerce platform as merchant users. Similarly, consumers in business activities, including actual or potential consumers, can use online services on the e-commerce platform as consumer users. In actual business activities, the same entity can act as both a merchant user and a consumer user; this should be understood flexibly.

[0030] The infrastructure used to deploy e-commerce platforms mainly includes the backend architecture (such as...). Figure 1 (servers in the middle) and front-end devices (such as Figure 1 The client-side architecture runs various online services through a service cluster, including middleware or front-end services for the platform, services for consumers, and services for merchants, to enrich and improve its service functions; the front-end devices mainly cover the terminal devices used by users as clients to access the e-commerce platform, including but not limited to various mobile terminals, personal computers, point-of-sale devices, etc.

[0031] In some embodiments, the e-commerce platform may be implemented through a processing facility including a processor and memory, which stores a set of instructions that, when executed, cause the e-commerce platform to perform the image processing functions involved in this application. The processing facility may be part of a server, client, network infrastructure, mobile computing platform, cloud computing platform, fixed computing platform, or other computing platform, and may provide electronic components of the e-commerce platform, merchant devices, payment gateways, application developers, marketing channels, transportation providers, customer devices, point-of-sale devices, etc.

[0032] E-commerce platforms can provide online services such as cloud computing services, Software as a Service (SaaS), Infrastructure as a Service (IaaS), Platform as a Service (PaaS), Desktop as a Service (DaaS), Hosted Software as a Service, Mobile Backend as a Service (MBaaS), and IT Management as a Service (ITMaaS). In some embodiments, the various functional components of the e-commerce platform 10 can be implemented to operate on various platforms and operating systems. For example, for an online store, its administrator user can operate on various platforms and operating systems, regardless of whether it is iOS or Android. TM、 Android TM HomonyOS TM In various embodiments, such as web pages, they all enjoy the same or similar functions.

[0033] E-commerce platforms can provide merchants with their own independent websites to run their online stores. They offer corresponding business management engine instances for merchants to build, maintain, and run one or more online stores across one or more independent websites. These business management engine instances can be used for content management, task automation, and data management for one or more online stores. They can be configured with various specific business processes of the online store through interfaces or built-in components to support business activities.

[0034] The image generation method provided in this application can be programmed into a computer program product and deployed on a client or server for execution. For example, in an exemplary application scenario of this application, it can be deployed on the server of an e-commerce customer service platform. In this way, the method can be executed by human-computer interaction with the process of the computer program product through a graphical user interface by accessing the interface opened after the computer program product is running.

[0035] refer to Figure 2 The diagram shown is a flowchart of an image generation method provided in some embodiments of this application. The image generation method is applied in a server. Figure 2 The example method includes one or more steps, but does not constitute a limitation of this application. Furthermore, the order of the steps in the method is merely illustrative and may be changed. Additional steps may be added or steps may be removed without departing from the disclosure of this application. The method includes the following steps.

[0036] Step S201: Receive the image generation request sent by the client, and parse the first image data of the image generation request into second image data in a preset format.

[0037] In some embodiments of this application, the client responds to a user's operation and generates an image generation request. In some embodiments of this application, the client's web browser or app responds to a user's action of clicking a preset button on the web browser or app and generates an image generation request. In some embodiments of this application, the image generation request includes image data (e.g., data data), which is encapsulated in the JOSN body of the image generation request. The server parses the first image data into second image data in a preset format.

[0038] In some embodiments of this application, parsing the first image data into second image content includes: calling a receipt data generation API to parse the first image data into second image data in a preset format, where the preset format includes HyperText Markup Language (HTML) and Scalable Vector Graphics (SVG). Specifically, the server obtains JavaScript Object Notation (JSON) image data from the image generation request, fills the JSON image data into placeholders in the HTML template file to obtain HTML image data, or fills the JSON image data into placeholders in the SVG template file to obtain SVG image data.

[0039] Step S202: Convert the second image data into a bitmap image using a preset rendering engine.

[0040] In some embodiments of this application, the default rendering engine is the Satori engine, which can render HTML image data or SVG image data into bitmap or vector graphics. In some embodiments of this application, the bitmap image is a Portable Network Graphics (PNG) image or a Joint Photographic Experts Group (JPRG) image.

[0041] In some embodiments of this application, converting second image data into a bitmap image using a preset rendering engine includes: converting second image data in a preset format into a JSX object; generating an SVG string using the Satori engine based on the JSX object and preset layout information; and converting the SVG string into a bitmap image. In some embodiments of this application, the layout information includes, but is not limited to, canvas size and font information. In some embodiments of this application, converting the SVG string into a bitmap image includes: rasterizing the SVG string into a pixel bitmap to obtain a bitmap image.

[0042] Step S203: Compress and convert the bitmap image to obtain the target image.

[0043] In some embodiments of this application, the Sharp image processing library is used to compress and convert the format of bitmap images to obtain the target image. In some embodiments of this application, the Sharp image processing library is a Node.js image processing module. In some embodiments of this application, compressing bitmap images using the Sharp image processing library includes: compressing the bitmap image using a preset compression algorithm and parameters of the Sharp image processing library. The preset compression algorithm includes, but is not limited to, a lossy compression algorithm based on discrete cosine transform and a lossless compression algorithm based on the DEFLATE algorithm. The parameters include, but are not limited to, a quality factor and a compression level. The embodiments of this application use the Sharp image processing library to compress bitmap images, which can reduce the file size of the target image, thereby helping to improve the webpage loading speed of the target image, reduce the storage space required to store the target image, and reduce the bandwidth consumption for transmitting the target image.

[0044] In some embodiments of this application, format conversion of bitmap images using the Sharp image processing library includes converting the bitmap image from a first format to a second format. The first format can be PNG, and the second format includes PNG, JPEG, and Web Picture format (WEBP). In this embodiment, format conversion of the bitmap image ensures that the output target image has a uniform format.

[0045] In some embodiments of this application, the Satori engine employs an asynchronous processing mechanism to render HTML or SVG image data into bitmap images, significantly reducing rendering time. Embodiments of this application convert bitmap images to obtain target images, and can generate images in various formats according to user needs. When compressing bitmap images, embodiments of this application can use either a lossless compression algorithm or a lossless compression algorithm as needed, thereby enabling adjustment of image quality according to user requirements.

[0046] Step S204: Return the target image to the client.

[0047] In some embodiments of this application, the server returns the target image generated in real time to the client.

[0048] Step S205: Store the target image.

[0049] In some real-time examples of this application, the generated target image is cached in memory. This allows the server to quickly respond to repeated requests from the client, directly retrieving the target image from memory and returning it to the client, thus reducing the server's workload. In some embodiments of this application, the memory includes a cache from a remote dictionary server (Redis).

[0050] In this embodiment, the server returns the target image generated in real time to the client. Since the target image has been compressed and converted, this application can reduce the bandwidth required for target image transmission, and the client can quickly load the target image, thus solving the technical problem of high operating overhead and long response time when the client generates images.

[0051] The following combination Figure 1 This application provides a detailed description of the image generation method according to its embodiments. (See also...) Figure 3 The diagram shown is a flowchart of an image generation method provided in some other embodiments of this application. The method includes the following steps.

[0052] Step S301: The client responds to the user's operation and generates an image generation request.

[0053] In some embodiments of this application, an image viewing button is displayed on the application interface of the client's web browser or APP. The client generates an image generation request in response to the user's click on the image viewing button. In some embodiments of this application, the image generation request includes image data, which is encapsulated in the JOSN body of the image generation request.

[0054] In step S302, the server's load balancer receives the image generation request sent by the client and sends the image generation request to the API gateway instance in the gateway layer.

[0055] In some embodiments of this application, the load balancer sends the image generation request to the gateway instance according to a preset load balancing algorithm. In some embodiments of this application, the preset load balancing algorithm includes a static load balancing algorithm and a dynamic load balancing algorithm. Step S303: The API gateway instance verifies the image generation request.

[0056] In some embodiments of this application, the API gateway instance verifies the image generation request by: obtaining a first key from the request header of the image generation request, comparing the obtained first key with a stored second key to authenticate the image generation request; if the first key and the second key are consistent, the authentication is determined to be successful; if the first key and the second key are inconsistent, the authentication is determined to be unsuccessful.

[0057] In some embodiments of this application, the API gateway instance of the gateway verifies the image generation request by: detecting whether the number of times the image generation request is received within a preset time period reaches a preset number, so as to perform security verification on the image generation request; if the number of times the image generation request is received within the preset time period does not reach the preset number, the security verification is determined to be successful; if the number of times the image generation request is received within the preset time period reaches the preset number, the security verification is determined to be successful.

[0058] Step S304: After successful verification, the API gateway instance sends the image generation request to the corresponding service instance in the application service layer.

[0059] In some embodiments of this application, after successful verification, the API gateway instance sends the image generation request to the corresponding service instance in the application service layer, so that the corresponding service instance can process the image generation request.

[0060] In step S305, the service instance parses the first image data of the image generation request into second image data in a preset format, and performs data verification on the second image data.

[0061] In some embodiments of this application, the service instance parses the first image data into second image data by: calling a receipt data generation API to parse the first image data into second image data. Preset formats include, but are not limited to, HTML and SVG. Specifically, the service instance obtains JSON image data from the image generation request, fills the JSON image data into placeholders in an HTML template file to obtain HTML image data, or fills the JSON image data into placeholders in an SVG template file to obtain SVG image data.

[0062] In some embodiments of this application, data verification of the second image data includes: detecting whether the required fields in the second image data have been filled in; detecting whether the field format and field type in the second image data conform to business rules; if the required fields have been filled in and the field format and field type conform to business rules, the second image data is determined to have passed data verification.

[0063] Step S306: After the second image data passes data verification, the service instance searches the Redis cache based on the configuration parameters in the second image data to determine whether an image matching the configuration parameters exists in the Redis cache. If an image matching the configuration parameters exists in the Redis cache, proceed to step S307; otherwise, proceed to step S308.

[0064] In some embodiments of this application, the service instance's method of searching the Redis cache based on configuration parameters in the second image data to determine whether an image matching the configuration parameters exists in the Redis cache includes: the service instance generating a hash value from the configuration parameters of the second image data using a hash function; combining the hash value with business information to generate a target cache identifier; searching the Redis cache based on the target cache identifier to detect whether a cache identifier matching the target cache identifier exists in the Redis cache; if a cache identifier matching the target cache identifier exists in the Redis cache, it is determined that an image matching the configuration parameters exists in the Redis cache; if no cache identifier matching the target cache identifier exists in the Redis cache, it is determined that no image matching the configuration parameters exists in the Redis cache. In some embodiments of this application, the hash function includes the MD5 function. The business information includes the command identifier of the image generation request and the client's identity identifier.

[0065] In step S307, the service instance uses the image stored in the Redis cache that matches the configuration parameters as the target image and returns the target image to the client.

[0066] In this embodiment of the application, when an image matching the configuration parameters exists in the Redis cache, the image stored in the Redis cache that matches the configuration parameters is directly used as the target image, and the target image is returned to the client. This can reduce resource overhead, reduce image generation response time, and improve image generation efficiency.

[0067] In step S308, the service instance uses a preset rendering engine to convert the second image data into a bitmap image.

[0068] In some embodiments of this application, the default rendering engine is the Satori engine, which can render HTML image data or SVG image data into bitmap or vector graphics. In some embodiments of this application, the bitmap image is a PNG image or a JPRG image.

[0069] In some embodiments of this application, converting the second image data into a bitmap image using a preset rendering engine includes: converting the second image data into a JSX object; the Satori engine generating an SVG string based on the JSX object and preset layout information; and converting the SVG string into a bitmap image. In some embodiments of this application, the layout information includes, but is not limited to, canvas size and font information. In some embodiments of this application, converting the SVG string into a bitmap image includes: rasterizing the SVG string into a pixel bitmap to obtain a bitmap image.

[0070] In step S309, the service instance returns the target image to the client.

[0071] In step S310, the service instance stores the target image on the disk of the server's file storage layer.

[0072] Step S311: The service instance generates a cache identifier based on the configuration parameters and business information of the target image, and stores the target image in the Redis cache according to the cache identifier.

[0073] In this embodiment, when the service instance receives the same image request again, it directly retrieves the corresponding image from the Redis cache and returns it to the client. This reduces the response time required for image generation and improves response speed.

[0074] In some embodiments of this application, the service instance returns the target image generated in real time to the client. Since the target image has been compressed and converted in format, the bandwidth required for target image transmission can be reduced, and the client can load the target image quickly. This solves the technical problem of high operating overhead and long response time when the client generates images.

[0075] refer to Figure 4 The diagram shown is a flowchart of a method for converting second image data into a bitmap image according to some embodiments of this application. The method includes the following steps.

[0076] Step S401: The service instance loads Chinese font resources.

[0077] In some embodiments of this application, the service instance loads the Source Han Sans font file from the server's disk into memory.

[0078] In step S402, the service instance uses the second image data to define the structure and style of the image using a JSX object to obtain JSX (JavaScript XML) elements, optimizes the JSX elements using the Satori engine, and converts them into a layout model based on Flexbox.

[0079] In some embodiments of this application, the layout model represents a flattened element tree model.

[0080] Step S403: Based on the Satori engine, the service instance determines the SVG string according to the Chinese font resources and layout model.

[0081] In some embodiments of this application, the Satori engine outputs the SVG string based on the Chinese font resources and layout model, after layout calculation. In some embodiments of this application, the layout calculation is used to determine the text width, line breaks, and layout information. The layout calculation includes typography calculation and positioning calculation.

[0082] In step S404, the service instance uses the Sharp image processing library to convert the SVG string into a bitmap image, and then compresses and converts the bitmap image to obtain the target image.

[0083] In some embodiments of this application, compressing bitmap images includes: compressing the bitmap image using a preset compression algorithm and parameters from the Sharp image processing library. The preset compression algorithm includes, but is not limited to, a lossy compression algorithm based on discrete cosine transform and a lossless compression algorithm based on the DEFLATE algorithm. The parameters include, but are not limited to, a quality factor and a compression level. By using the Sharp image processing library to compress bitmap images in this application, the file size of the target image can be reduced, thereby helping to improve the webpage loading speed of the target image, reduce the storage space required to store the target image, and reduce the bandwidth consumption for transmitting the target image.

[0084] In some embodiments of this application, converting a bitmap image to a format includes converting the bitmap image from a first format to a second format. The first format may be PNG, and the second format may include PNG, JPEG, or WEBP.

[0085] Please refer to Figure 5 The diagram shown is a structural schematic of an electronic device provided in some embodiments of this application. The electronic device 50 may include at least one memory 51, a processor 52, and a communication unit 53. The memory 51 includes a computer-readable storage medium for storing computer programs, such as multiple logical instructions. The communication unit 53 is used to communicate with the electronic device 50 or a server. The processor 52 can execute the logical instructions to perform the aforementioned image generation method.

[0086] It is understood that in some embodiments, the communication unit 53 includes modules with communication functions such as network modules, and this application does not limit this.

[0087] The logical instructions in the aforementioned computer-readable storage medium can be implemented in the form of software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.

[0088] The computer-readable storage medium may be configured to store software programs or computer-executable programs, such as the program instructions corresponding to the image generation method in the embodiments of this application. The processor 52 executes functional applications and image processing by running the software programs, instructions, or modules stored in the computer-readable storage medium, thereby implementing the image generation method in the above embodiments.

[0089] In embodiments of this application, the computer-readable storage medium includes non-volatile computer-readable storage media, such as disks, memory, etc. It is understood that the computer-readable storage medium may also include other non-volatile computer-readable storage media, such as plug-in hard disks, smart media cards (SMCs), secure digital (SD) cards, flash cards, at least one flash memory device, and / or other non-volatile solid-state storage devices.

[0090] In this embodiment, the processor 52 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 52 is the control center of the electronic device 50, and can connect to other external devices and / or systems / modules / units using various interfaces and lines to provide base sequencing functionality to the applications of other external devices and / or systems / modules / units.

[0091] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned steps to implement the image generation method described above.

[0092] In this embodiment, the electronic device, computer storage medium, computer program product or chip are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding method provided above, and will not be repeated here.

[0093] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0094] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0095] The unit described as a separate component may or may not be physically separate. The component shown as a unit can be one physical unit or multiple physical units, that is, it can be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of the solution in this embodiment according to actual needs.

[0096] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0097] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0098] The above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to the above preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions to the technical solutions of this application should not depart from the spirit and scope of the technical solutions of this application.

Claims

1. An image generation method, applied in a server, characterized in that, The method includes: Receive an image generation request sent by the client, and parse the first image data of the image generation request into second image data in a preset format; The second image data is converted into a bitmap image using a preset rendering engine; The bitmap image is compressed and its format converted to obtain the target image. The target image is returned to the client.

2. The image generation method as described in claim 1, characterized in that, The step of receiving the image generation request sent by the client and parsing the first image data of the image generation request into second image data in a preset format includes: The server's load balancer receives the image generation request sent by the client and sends the image generation request to the server's gateway layer's API gateway instance. After the image generation request is verified, the API gateway instance sends the image generation request to the corresponding service instance in the application service layer of the server. The service instance parses the first image data into the second image data.

3. The image generation method as described in claim 2, characterized in that, Verification of the image generation request includes: Obtain the first key from the request header of the image generation request; The first key is compared with the stored second key to authenticate the image generation request; If the first key matches the second key, the authentication of the image generation request is confirmed to be successful. If the first key and the second key are inconsistent, it is determined that the authentication of the image generation request has failed.

4. The image generation method as described in claim 2, characterized in that, The service instance parses the first image data into the second image data as follows: The service instance obtains JSON image data from the image generation request, fills the JSON image data into placeholders in the Hypertext Markup Language (HTML) template file to obtain HTML image data, or fills the JSON image data into placeholders in the Scalable Vector Graphics (SVG) template file to obtain SVG image data.

5. The image generation method as described in claim 4, characterized in that, The method further includes: Check whether the required fields in the second image data have been filled in; Detect whether the field format and field type in the second image data conform to business rules; If the required fields are filled in and the field format and field type conform to the business rules, the second image data is determined to pass data verification.

6. The image generation method as described in claim 5, characterized in that, The method further includes: After the second image data passes data verification, the service instance searches the remote dictionary server Redis cache based on the configuration parameters in the second image data to determine whether there is an image in the Redis cache that matches the configuration parameters. If an image matching the configuration parameters exists in the Redis cache, the service instance uses the image matching the configuration parameters stored in the Redis cache as the target image and returns the target image to the client. If no image matching the configuration parameters exists in the Redis cache, the service instance uses the preset rendering engine to convert the second image data into the bitmap image.

7. The image generation method as described in claim 6, characterized in that, The service instance uses the preset rendering engine to convert the second image data into the bitmap image, including: Load Chinese font resources; Based on the second image data, the structure and style of the image are defined using JSX objects to obtain JSX elements. The JSX elements are then optimized using a preset rendering engine and converted into a layout model based on Flexbox. Based on the preset rendering engine, the SVG string is determined according to the Chinese font resources and the layout model; Using the Sharp image processing library, the SVG string is converted into a bitmap image, and the bitmap image is compressed and converted to obtain the target image.

8. The image generation method as described in claim 7, characterized in that, The compression of the bitmap image includes: The bitmap image is compressed using the preset compression algorithm and parameters of the Sharp image processing library.

9. An electronic device, characterized in that, The electronic device includes a memory and a processor: The memory is used to store program instructions; The processor is configured to read and execute the program instructions stored in the memory, and when the program instructions are executed by the processor, cause the electronic device to perform the image generation method as described in any one of claims 1 to 8.

10. A computer storage medium, characterized in that, The computer storage medium stores program instructions that, when executed on an electronic device, cause the electronic device to perform the image generation method as described in any one of claims 1 to 8.

Citation Information

Cited By

  • Cloud dynamic dot-matrix font service method and system

    CN121771237A