Picture format conversion method and device, computer equipment and storage medium

By obtaining and processing configuration parameters and label information in the document object model and generating PNG pictures, the problem of complex and inefficient conversion of SVG pictures to PNG pictures is solved, efficient one-click conversion is achieved, and data security is improved.

CN119065565APending Publication Date: 2024-12-03ZHENGZHOU INSPUR DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411052344.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-12-03

AI Technical Summary

Technical Problem

In the prior art, the process of converting SVG pictures to PNG pictures is complicated and inefficient, and there are data security problems.

Method used

By obtaining the target configuration parameters in the current document object model, performing image data processing and label matching, generating parsed files, and generating target images based on parsed files and target configuration parameters, realizing one-click conversion of image format conversion.

Benefits of technology

It improves the efficiency of image conversion, simplifies the process, avoids dependence on external resources, ensures the consistency of image presentation effects, and solves data security problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119065565A_ABST
    Figure CN119065565A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of picture conversion, and discloses a picture format conversion method and device, computer equipment and a storage medium, and the method comprises the steps: obtaining a target configuration parameter corresponding to a current picture in a current document object model in response to the triggering of a format conversion key; performing data processing and label matching on the picture data of the current picture to obtain an analysis file corresponding to the current picture; the analysis file comprises picture data of the current picture and multiple pieces of label information; and based on the target configuration parameter and the analysis file, generating and downloading a picture in the first picture format to obtain a target picture. Therefore, after the format conversion key is triggered, the picture data is subjected to data processing and label matching to obtain the corresponding analysis file, and the picture in the first picture format is generated based on the corresponding analysis file and the set target configuration parameters, so that one-key conversion of picture format conversion is realized, and the picture conversion efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of picture conversion, and in particular to a picture format conversion method, device, computer equipment and storage medium. Background Art

[0002] SVG (Scalable Vector Graphics) is an image format based on XML (Extensible Markup Language) that supports high-quality graphics rendering and is suitable for a variety of display devices and resolutions. However, in some application scenarios, there is still a demand for bitmap formats, such as PNG format images. At present, the main method is to download SVG images locally, and then use graphic design software or online conversion tools to convert SVG images into PNG images. The process of converting image formats using this method is complicated and cumbersome, and the efficiency of image conversion is relatively low. Summary of the invention

[0003] In view of this, the present invention provides a method, apparatus, computer device and storage medium for converting picture formats to solve the problem of low efficiency of picture conversion.

[0004] In a first aspect, the present invention provides a method for converting a picture format, the method comprising:

[0005] In response to the triggering of the format conversion button, the target configuration parameters corresponding to the current picture in the current document object model are obtained; the target configuration parameters are picture parameters of the target picture obtained by converting the current picture; the picture format of the target picture is the first picture format;

[0006] Perform data processing and label matching on the image data of the current image to obtain a parsing file corresponding to the current image; the parsing file includes the image data of the current image and multiple label information;

[0007] Based on the target configuration parameters and the parsed file, a picture in a first picture format is generated and downloaded to obtain a target picture.

[0008] In this way, after the format conversion button is triggered, the image data in the current document object model is processed and labeled to obtain its corresponding parsed file, and based on the corresponding parsed file and the set target configuration parameters, a picture in the first picture format is generated, thereby realizing one-click conversion of picture formats and improving the efficiency of picture conversion.

[0009] In an optional implementation, in response to triggering of the format conversion button, obtaining target configuration parameters corresponding to the current image in the current document object model includes:

[0010] In response to the triggering of the format conversion button, a parameter configuration interface is displayed on the current interface; the parameter configuration interface is used to provide an interactive interface for inputting configuration parameters;

[0011] In response to the interaction with the parameter configuration interface, the configuration parameters input in the parameter configuration interface are acquired, and the input configuration parameters are used as target configuration parameters.

[0012] In this way, by providing a parameter configuration interface to the user, the user can input the required configuration parameters of the target image in the parameter configuration interface, thereby obtaining the target configuration parameters of the target image, and generating the target image based on the parameters.

[0013] In an optional implementation, data processing and label matching are performed on the image data of the current image to obtain a parsed file corresponding to the current image, including:

[0014] Add the file header information and attribute information corresponding to the parsed file to the data of the current image to obtain the initial parsed file;

[0015] Call the style sheet access interface to obtain the style sheet of the current interface;

[0016] Match the font value in the style sheet to obtain the font tag information corresponding to the current image;

[0017] Match the style in the current image with the style in the style sheet to obtain the style tag information corresponding to the current image;

[0018] Obtain each picture element in the current picture and the address information of each picture element, and based on the address information of the picture element, obtain the data stream corresponding to the picture element;

[0019] The font tag information and the style tag information are written into the tag of the initial parsed file, and the address information of the picture element is replaced with the data stream corresponding to the picture element to obtain the parsed file.

[0020] In this way, the font and style related to the current picture are written into the initial parsing file as tag information, and the data stream of the picture elements in the current picture is written into the initial parsing file to obtain the parsing file, so that the parsing file contains all relevant factors of the picture presentation effect of the current picture, thereby ensuring that the picture presentation effect of the target picture generated based on the parsing file is consistent with the current picture.

[0021] In an optional implementation, matching the font value in the style sheet to determine the font tag information corresponding to the current image includes:

[0022] If the font value includes the first target value, the font value is used as the font tag information;

[0023] If the font value includes the second target value, the type information and font information corresponding to the font value are determined, and the type information and font information are used as font tag information.

[0024] In this way, different types of font values ​​are processed differently to obtain their corresponding font tag information.

[0025] In an optional implementation, the style in the current image is matched with the style in the style sheet to obtain style tag information corresponding to the current image, including:

[0026] If the target style in the style sheet matches the style in the current image, the target style is used as the style tag information.

[0027] In this way, the style in the current image is matched with the style in the style sheet, and the style existing in the current image is used as style tag information.

[0028] In an optional implementation, based on the target configuration parameters and the parsed file, generating and downloading a picture in a first picture format to obtain a target picture includes:

[0029] Perform character conversion on the parsed file to obtain the data stream corresponding to the current image;

[0030] Create a picture object and set the data stream corresponding to the current picture as the picture display data of the picture object;

[0031] Set the image parameters of the image object based on the target configuration parameters;

[0032] Based on the picture display data and the picture parameters, draw the picture, and convert the drawn picture into a data stream in a first picture format to obtain a data stream corresponding to the target picture;

[0033] Create a target storage object and store the data stream corresponding to the target image in the target storage object;

[0034] If the current interface supports the object opening interface corresponding to the target storage object, the object opening interface is called to obtain the data stream corresponding to the target image;

[0035] Download the target image based on the download address and image name in the target configuration parameters;

[0036] If the current interface does not support the object opening interface corresponding to the target storage object, create a download tag corresponding to the target storage object, and configure the download path and image name in the download tag;

[0037] Trigger the click event corresponding to the download tag to trigger and execute the download tag to download the target image.

[0038] In this way, based on the parsed file and the target configuration parameters, the data stream corresponding to the target image is obtained, and according to the download address and image name configured in the target configuration parameters, the data stream corresponding to the target image is downloaded to obtain the target image.

[0039] In an optional embodiment, the method further includes:

[0040] Get the current address information of the current interface and match the current address information with the target address information;

[0041] If the current address information matches the target address information, a format conversion button is provided to the current interface, and the format conversion button is set to a non-triggerable state;

[0042] Get the current document object model and determine the image format corresponding to the current image in the current document object model;

[0043] If the image format is the second image format, the format conversion button is set to a triggerable state.

[0044] Thus, when the current interface is the interface corresponding to the target address information and the currently selected picture in the current interface is in the second picture format, the format conversion button is set to a triggerable state to ensure that the picture to be format converted is in the second picture format.

[0045] In a second aspect, the present invention provides a device for converting picture formats, the device comprising:

[0046] The configuration parameter acquisition module is used to obtain the target configuration parameters corresponding to the current picture in the current document object model in response to the triggering of the format conversion button; the target configuration parameters are the image parameters of the target image obtained by converting the current image; the image format of the target image is the first image format;

[0047] The parsing file acquisition module is used to perform data processing and label matching on the image data of the current image to obtain the parsing file corresponding to the current image; the parsing file includes the image data of the current image and multiple label information;

[0048] The target image generation module is used to generate and download an image in a first image format based on target configuration parameters and a parsed file to obtain a target image.

[0049] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the image format conversion method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0050] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the image format conversion method of the first aspect or any corresponding embodiment thereof.

[0051] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the image format conversion method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0053] Figure 1 is a schematic diagram of a process of a method for converting picture formats according to an embodiment of the present invention;

[0054] Figure 2 is a schematic flow chart of another method for converting picture formats according to an embodiment of the present invention;

[0055] Figure 3 is a schematic diagram of a parameter configuration interface according to an embodiment of the present invention;

[0056] Figure 4 A schematic diagram of a method for converting picture formats according to an embodiment of the present invention;

[0057] Figure 5 is a flowchart of another method for converting picture formats according to an embodiment of the present invention;

[0058] Figure 6 is a schematic diagram of inline processing of picture elements according to an embodiment of the present invention;

[0059] Figure 7 is a structural block diagram of a device for converting picture formats according to an embodiment of the present invention;

[0060] Figure 8 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0061] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0062] SVG (Scalable Vector Graphics) is an image format based on XML (Extensible Markup Language) that supports high-quality graphics rendering and is suitable for a variety of display devices and resolutions. However, in some application scenarios, there is still a demand for bitmap formats, such as PNG format images; for example, when document engineers write documents for virtualization products, they often need to reflect the SVG graphics in the original interface in the document in PNG format. If the PNG image is replaced by a screenshot of the SVG image in the interface, although the efficiency is high, the image quality will be seriously reduced. If the SVG image is downloaded locally, and then converted into a PNG image with the help of graphic design software or online conversion tools, and finally embedded in the document, although the image quality can be improved, the process is complicated and cumbersome, and the efficiency of image conversion is relatively low. At the same time, graphic design software or online conversion tools often rely on their own services. When converting the downloaded SVG, there are potential data security issues.

[0063] Based on this, an embodiment of the present invention provides a method for converting a picture format, including: in response to the triggering of a format conversion button, obtaining target configuration parameters corresponding to the current picture in the current document object model; the target configuration parameters are picture parameters of the target picture obtained by the conversion of the current picture; the picture format of the target picture is a first picture format; data processing and label matching are performed on the picture data of the current picture to obtain a parsed file corresponding to the current picture; the parsed file includes the picture data of the current picture and a plurality of label information; based on the target configuration parameters and the parsed file, a picture in the first picture format is generated and downloaded to obtain the target picture. In this way, after the format conversion button is triggered, the picture data in the current document object model is processed and matched with labels to obtain its corresponding parsed file, and based on the corresponding parsed file and the set target configuration parameters, a picture in the first picture format is generated, thereby realizing one-key conversion of picture format conversion and improving the efficiency of picture conversion.

[0064] According to an embodiment of the present invention, an embodiment of a method for converting image format is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0065] In this embodiment, a method for converting picture formats is provided, which can be used in a mobile terminal. Figure 1 is a flowchart of a method for converting picture formats according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0066] Step S101, in response to the triggering of the format conversion button, obtaining the target configuration parameters corresponding to the current image in the current document object model.

[0067] In an embodiment of the present invention, the format conversion button is a button set in the current interface for triggering image format conversion, which is displayed and provided to the user when the document object model in the current interface is selected or right-clicked. The target configuration parameters are image parameters of the target image obtained by converting the current image, and the target configuration parameters are input by the user after triggering the format conversion button. The image format of the target image is a first image format, and specifically, the first image format may be a bitmap format, such as a PNG format.

[0068] Step S102, performing data processing and label matching on the image data of the current image to obtain a parsed file corresponding to the current image.

[0069] In an embodiment of the present invention, the parsed file includes the image data of the current image and multiple tag information. Since the current image is an image in the second image format, that is, an image in the SVG format, its image presentation effect is related to some external resources, so it is necessary to perform data processing and tag matching on the image data of the current image, inline these related external resources, integrate them into the tag information of the current image, and obtain the parsed file corresponding to the current image, so that the parsed file contains all the information of the current image, and the image presentation effect of the current image can be restored only by parsing the file without the help of external resources.

[0070] Step S103: Generate and download a picture in a first picture format based on the target configuration parameters and the parsed file to obtain a target picture.

[0071] In an embodiment of the present invention, the size of the generated picture in the first picture format is limited based on the target configuration parameters; at the same time, based on the data contained in the parsed file, the picture in the first picture format is generated so that the picture presentation effect of the generated picture is consistent with the current picture, thereby obtaining the target picture.

[0072] In an optional implementation, first, character conversion processing is performed on the parsed file to obtain a data stream corresponding to the current image; the character conversion processing of the parsed file may include conversion processing of special symbols, such as processing spaces in the parsed file as '%25', and then converting the parsed file into a base64 encoded string, and concatenating "data:image / svg+xml;base64," at its header to obtain a data stream corresponding to the current image. Then, a picture object is established, and the data stream corresponding to the current picture is set as the picture display data of the picture object, that is, the src attribute of the picture object is set to the data stream corresponding to the current picture; based on the target configuration parameters, the picture parameters of the picture object are set, specifically, based on the size-related parameters in the target configuration parameters, that is, the picture height and the picture width, the picture parameters of the picture object are set. Based on the picture display data and the picture parameters, a picture is drawn, and the drawn picture is converted into a data stream of the first picture format to obtain a data stream corresponding to the target picture. Specifically, through the Canvas technology, the image object is passed in, and the width, height, etc. of the Canvas canvas are set according to the image parameters of the image object. The image is drawn on the Canvas canvas according to the image display data of the image object, and then the canvas is converted into a data stream in the first image format through the toDataURL API of the Canvas technology.

[0073] In an optional implementation, in order to save and download the target image, a target storage object is established, and the data stream corresponding to the target image is stored in the target storage object. The target storage object may be a Blob object, which is used to store large files or binary data blocks, such as images, audio, video, etc. Therefore, the Blob object is used to store the data volume corresponding to the target image.

[0074] In an optional implementation, considering that the current interface may not support the object opening interface corresponding to the target storage object, that is, the navigator.msSaveOrOpenBlob API interface, the target image is downloaded and obtained in the following two cases:

[0075] In the first case, if the current interface supports the object opening interface corresponding to the target storage object, the object opening interface can be directly called to obtain the data stream corresponding to the target image; based on the download address and image name in the target configuration parameters, the target image is downloaded to the address corresponding to the download address, and the target image is named with the image name, and finally the target image is downloaded.

[0076] In the second case, if the current interface does not support the object opening interface corresponding to the target storage object, a download tag corresponding to the target storage object is created, and the download path and image name are configured in the download tag; a click event corresponding to the download tag is triggered to trigger and execute the download tag to download the target image. Label, The tag is used for users to click text, pictures or other content to jump to another page or download files. At the same time, the href attribute of the download tag is assigned to URL.createObjectURL(Blob), thereby associating the download tag with the target storage object; by setting the download tag to hidden Tag, and automatically trigger the click event of the download tag, so as to automatically execute the action corresponding to the download tag and download the target image.

[0077] Thus, through the above method, based on the parsed file and the target configuration parameters, the data stream corresponding to the target image is obtained, and according to the download address and image name configured in the target configuration parameters, the data stream corresponding to the target image is downloaded to obtain the target image.

[0078] In this embodiment, a method for converting picture formats is provided, which can be used in a mobile terminal. Figure 2 is a flowchart of another picture format conversion method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0079] Step S201, in response to the triggering of the format conversion button, obtaining the target configuration parameters corresponding to the current image in the current document object model.

[0080] Specifically, step S201 includes:

[0081] Step S2011, in response to the triggering of the format conversion button, displaying the parameter configuration interface on the current interface.

[0082] In the embodiment of the present invention, the parameter configuration interface is used to provide an interactive interface for inputting configuration parameters. When the format conversion button is triggered, that is, when the user clicks the format conversion button, the parameter configuration interface is displayed in the current interface.

[0083] In an optional embodiment, Figure 3 is a schematic diagram of a parameter configuration interface according to an embodiment of the present invention, such as Figure 3 As shown, the parameter configuration interface provides the user with an area for configuring the target image's image name, image width, image height, and download path. Enter the name the user wants to give the target image in the area corresponding to the image name, enter the width of the target image required by the user in the area corresponding to the image width, enter the height of the target image required by the user in the area corresponding to the image height, and enter the path corresponding to the address to which the user wants to download the target image in the area corresponding to the download path. Optionally, a selection button can be set, and the selection button can be associated with an existing path, so that the existing path can be opened by triggering the selection button, and the download path can be selected from the existing path, thereby improving the efficiency and accuracy of the download path input.

[0084] Step S2012: in response to the interaction with the parameter configuration interface, obtaining the configuration parameters input in the parameter configuration interface, and taking the input configuration parameters as target configuration parameters.

[0085] In the embodiment of the present invention, in response to the interaction with the parameter configuration interface, specifically, Figure 3As shown, in response to the interaction and triggering of the determined button in the parameter configuration interface, the configuration parameters input in the parameter configuration interface are obtained, and the input configuration parameters are used as the target configuration parameters. Specifically, the input image width and image height are used to limit the size of the target image finally generated, the input image name is used as the name of the target image finally generated, and the input download path is used as the path when the target image finally generated is downloaded.

[0086] Therefore, through the above method, by providing a parameter configuration interface to the user, the user enters the configuration parameters of the required target image in the parameter configuration interface, thereby obtaining the target configuration parameters of the target image, and generating the target image based on this.

[0087] In an optional implementation, in order not to affect the operating efficiency of the interface and to ensure the security of other interfaces, a format conversion button is provided to the user only when the current interface is the target interface. Specifically, the current address information of the current interface is obtained, and the current address information is matched with the target address information; if the current address information matches the target address information, a format conversion button is provided to the current interface, and the format conversion button is set to an untriggerable state. Among them, the target address information is the address information corresponding to the target interface set internally, and the target address information can be a URL (Uniform Resource Locator) address. When the address corresponding to the target address information is accessed, that is, the current address information of the current interface is consistent with the target address information, the calling interface is added to the menu of the current interface. The format conversion button is set to gray, so that it is in an untriggerable state.

[0088] In an optional implementation, in order to ensure that the images to be format-converted are all in the second image format, that is, the SVG format, after providing a format conversion button in the forward interface and setting the format conversion button to a non-triggerable state, the current document object model is obtained, and the image format corresponding to the current image in the current document object model is determined; if the image format is the second image format, the format conversion button is set to a triggerable state. Among them, the current document object model is the document object model (Document Object Model, DOM) selected by the mouse controlled by the current user. When the image format of the current image in the current document object model is the second image format, that is, the SVG format, the format conversion button is set to a triggerable state so that the format conversion button can be triggered to convert the image format. Thus, when the current interface is the interface corresponding to the target address information, and the currently selected image in the current interface is in the second image format, the format conversion button is set to a triggerable state to ensure that the image to be format-converted is an image in the second image format.

[0089] In an optional embodiment, Figure 4 A schematic diagram of a method for converting picture formats according to an embodiment of the present invention is shown in FIG. Figure 4 As shown, the listening unit is used to monitor whether the current interface is the target interface, that is, to monitor whether the current address information of the current interface is the target address information, and to monitor the selection event of the current picture in the current document object module, so as to determine whether the current picture is a picture of the second picture format. The visual operation unit mainly includes the right-click menu of the mouse and the parameter configuration interface in the interface. The right-click menu of the mouse is the option menu for operating the current picture triggered after the selection event of the current picture. When the current picture is a picture of the second picture format, the format conversion button is set to a triggerable state. The parameter configuration interface is displayed in the current interface after the format conversion button is triggered, so that the user can input the target configuration parameters of the target image, and output the configuration parameters representing the size in the input target configuration parameters to the PNG construction unit, so that the PNG construction unit can obtain the parsed file, that is, SVG XML, by the SVG parsing unit, and then draw the PNG image, that is, the image in the first image format, and output the PNG data stream according to the SVG XML and the configuration parameters representing the size; the parameter configuration interface outputs the configuration parameters representing the path and the image name in the input target configuration parameters to the persistence unit, so that the persistence unit can download the PNG data stream output by the PNG construction unit to the address corresponding to the path, and name the image according to the image name to obtain the target image.

[0090] Step S202: Process the image data of the current image and perform label matching to obtain the parsed file corresponding to the current image. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0091] Step S203: Generate and download a picture in the first picture format based on the target configuration parameters and the parsed file to obtain the target picture. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.

[0092] In this embodiment, a method for converting picture formats is provided, which can be used in a mobile terminal. Figure 5 is a flowchart of another method for converting picture formats according to an embodiment of the present invention. Figure 5 As shown, the process includes the following steps:

[0093] Step S501, in response to the triggering of the format conversion button, obtain the target configuration parameters corresponding to the current image in the current document object model. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0094] Step S502: perform data processing and label matching on the image data of the current image to obtain a parsed file corresponding to the current image.

[0095] Specifically, step S502 includes:

[0096] Step S5021, adding file header information and attribute information corresponding to the parsed file to the data of the current image to obtain an initial parsed file.

[0097] In the embodiment of the present invention, an SVG XML file header and attributes such as xmlns:xlink are added to the acquired data of the current image, that is, the SVG DOM, so that it becomes a standard SVG XML file, and an initial parsed file is obtained.

[0098] Step S5022: call the style sheet access interface to obtain the style sheet of the current interface.

[0099] In the embodiment of the present invention, since the image presentation effect of the SVG format image depends on some external resources, such as the font type and style used in the current interface, it is necessary to inline these external resources and integrate them into the tag information of the current image. By calling the style sheet access interface, the style sheet of the current interface is obtained. The style sheet of the current interface contains all the styles of the current interface, so as to determine the external resources related to the current image from the style sheet of the current interface, specifically including font resources and style resources, and inline them and write them into the initial parsing file. Among them, the style sheet access interface can be the document.styleSheets API interface, which can be used to access and operate all style sheets loaded by the browser.

[0100] Step S5023, matching the font values ​​in the style sheet to obtain the font tag information corresponding to the current image.

[0101] In an embodiment of the present invention, the font values ​​in the style sheet are matched through regular matching, it is determined whether the font values ​​in the style sheet depend on external links, and the font values ​​that depend on external links are inlined, and the relevant information obtained from the external links is extracted and put into the initial parsing file as font tag information, so that the font-related information is saved in the initial parsing file, and the font-related information can be directly determined by parsing the file during subsequent image format conversion.

[0102] In an optional implementation, the font values ​​in the style sheet are matched, different types of font values ​​are processed differently, and the corresponding font tag information is obtained, which may include the following two cases:

[0103] In the first case, if the font value includes a first target value, wherein the first target value is a value representing that the font value is internal data, the first target value may include multiple values ​​to respectively correspond to different situations where the font value is internal data. For example, the first target value may include empty, starting with data:, and "about:blank", etc. At this time, since the font value itself is internal data, the font value can be directly used as font tag information.

[0104] In the second case, if the font value includes a second target value, where the second target value is to indicate that the font relies on an external link, the second target value can be "url", indicating that the font value uses an external link, then the type information and font information corresponding to the font value are determined at this time, and the type information and font information are used as font tag information. Specifically, the MIME type of the font is obtained through the suffix of the url in the font value to obtain the type information corresponding to the font value; the url is loaded through the XMLHttpRequest API, and the corresponding font binary file is converted into a base64-encoded string to obtain the font information corresponding to the font value; finally, the type information and font information are combined in the form of "url(data: type information; base64, font information)" as the font tag information.

[0105] Step S5024, matching the style in the current image with the style in the style sheet to obtain style tag information corresponding to the current image.

[0106] In an embodiment of the present invention, selectors of all styles in a style sheet are put into an array to construct a selector array, the selector array is traversed, and a selector search is performed in an initial parsed file to match the style in the style sheet with the style in the current image.

[0107] In an optional implementation, if the target style in the style sheet matches the style in the current image, the target style is used as the style tag information. Specifically, if the selector being searched has a match in the initial parsed file, it can be considered that the target style corresponding to the selector matches the style in the current image, and the target style will affect the display of the current image in the current interface, so the target style is used as the style tag information.

[0108] Step S5025, obtaining each picture element in the current picture and the address information of each picture element, and obtaining the data stream corresponding to the picture element based on the address information of the picture element.

[0109] In the embodiment of the present invention, since existing images may be introduced during the drawing process of the SVG image, it is necessary to inline the existing images introduced into the current image. Specifically, by calling querySelectorAll("image"), each image element in the current image is obtained, and these image elements are the existing images introduced into the current image; then the address information of each image element is obtained respectively, and the data stream corresponding to the image element is obtained, and the corresponding image element can be drawn and restored according to the data stream.

[0110] In an optional embodiment, Figure 6 is a schematic diagram of inline processing of picture elements according to an embodiment of the present invention, such as Figure 6 As shown, the address information of each image element is obtained through the href attribute of each image element, and then a new image object is created, and the src attribute of the newly created image object is set to the address information of the image element, that is, its href attribute. The src attribute can specify the URL address of the external resource to be embedded in the page, thereby realizing image loading. Then, through Canvas technology, the src attribute is used to draw the newly created image object on the Canvas canvas. After the drawing is completed, the canvas is converted into an image data stream through the Canvas toDataURL API. The converted image data stream is the data stream corresponding to the image element.

[0111] In an optional implementation, the downloaded target images can also be stored in a target image set, and each target image can be numbered in the target image set. The target image set can be stored locally or in the cloud. When the image data of the current image is processed and the image elements therein are inlined, the image elements can be compared with the images in the target image set, or the address information of the image elements can be compared with the address range of the target image set. If the image element is a picture in the target image set, that is, its address information is within the address range of the target image set, the number of the image element in the target image set can be used to replace its corresponding data stream. Since the target image set is stored locally or in the cloud, it is convenient to obtain and does not need to rely on external browser resources for searching, thereby reducing the amount of data in the parsed file. When the target image is subsequently generated according to the parsed file, the data stream of the image corresponding to the number is directly obtained from the target image set according to the number, thereby improving the efficiency of generating the target image.

[0112] Step S5026, writing the font tag information and the style tag information into the tag of the initial parsed file, replacing the address information of the picture element with the data stream corresponding to the picture element, and obtaining the parsed file.

[0113] In the embodiment of the present invention, the font tag information and the style tag information are written into the tag of the initial parsed file, thereby realizing the inline processing of the font and style, so that the parsed file contains the relevant information of the font and style. The address information of the picture element is replaced with the data stream corresponding to the picture element, thereby realizing the inline processing of the picture, so that the parsed file contains the relevant information of the picture. Thus, the parsed file is obtained, and the parsed file does not need to rely on external resources, and contains all the information of the current picture.

[0114] In an optional implementation, the font tag information and style tag information can be written into the tags of the initial parsed file by customizing CSS (Cascading Style Sheets), and then embedding the custom CSS into the style tag of the initial parsed file.

[0115] In an optional embodiment, if Figure 6 As shown, the data stream corresponding to the obtained picture element, that is, the picture data stream, replaces the href attribute of the picture element, that is, href = picture data stream, and the picture data stream is assigned to the href attribute, thereby replacing the address information of the picture element with the data stream corresponding to the picture element.

[0116] Through the above method, the font and style related to the current image are written into the initial parsing file as tag information, and the data stream of the image elements in the current image is written into the initial parsing file to obtain the parsing file, so that the parsing file contains all relevant factors of the image presentation effect of the current image, ensuring that the image presentation effect of the target image generated based on the parsing file is consistent with the current image.

[0117] Step S503: Generate and download a picture in the first picture format based on the target configuration parameters and the parsed file to obtain the target picture. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.

[0118] The image format conversion method provided by the embodiment of the present invention, after triggering the format conversion button, obtains the corresponding parsing file by performing data processing and label matching on the image data in the current document object model, and generates an image in the first image format based on the corresponding parsing file and the set target configuration parameters, thereby realizing one-click conversion of the image format and improving the efficiency of image conversion.

[0119] In this embodiment, a picture format conversion device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0120] This embodiment provides a picture format conversion device, such as Figure 7 As shown, including:

[0121] The configuration parameter acquisition module 701 is used to obtain the target configuration parameters corresponding to the current picture in the current document object model in response to the triggering of the format conversion button; the target configuration parameters are the image parameters of the target image obtained by converting the current image; the image format of the target image is the first image format;

[0122] The parsing file acquisition module 702 is used to perform data processing and label matching on the image data of the current image to obtain the parsing file corresponding to the current image; the parsing file includes the image data of the current image and multiple label information;

[0123] The target image generation module 703 is used to generate and download an image in a first image format based on the target configuration parameters and the parsed file to obtain a target image.

[0124] In an optional implementation, the configuration parameter acquisition module 701 includes:

[0125] The parameter configuration interface display unit is used to display the parameter configuration interface on the current interface in response to the triggering of the format conversion button; the parameter configuration interface is used to provide an interactive interface for inputting configuration parameters;

[0126] The configuration parameter acquisition unit is used to acquire the configuration parameters input in the parameter configuration interface in response to the interaction with the parameter configuration interface, and use the input configuration parameters as target configuration parameters.

[0127] In an optional implementation, the parsing file acquisition module 702 includes:

[0128] An initial parsed file acquisition unit, used to add file header information and attribute information corresponding to the parsed file to the data of the current image, to obtain an initial parsed file;

[0129] A style sheet acquisition unit, used to call a style sheet access interface to acquire the style sheet of the current interface;

[0130] A font tag information determination unit, used to match the font value in the style sheet to obtain the font tag information corresponding to the current image;

[0131] A style tag information determination unit, used to match the style in the current picture with the style in the style sheet to obtain the style tag information corresponding to the current picture;

[0132] A data stream acquisition unit, used to acquire each picture element in the current picture and address information of each picture element, and acquire a data stream corresponding to the picture element based on the address information of the picture element;

[0133] The parsed file acquisition unit is used to write the font tag information and the style tag information into the tag of the initial parsed file, replace the address information of the picture element with the data stream corresponding to the picture element, and obtain the parsed file.

[0134] In an optional implementation, the font tag information determining unit is used to:

[0135] If the font value includes the first target value, the font value is used as the font tag information;

[0136] If the font value includes the second target value, the type information and font information corresponding to the font value are determined, and the type information and font information are used as font tag information.

[0137] In an optional implementation, the style tag information determining unit is configured to:

[0138] If the target style in the style sheet matches the style in the current image, the target style is used as the style tag information.

[0139] In an optional implementation, the target image generation module 703 includes:

[0140] A parsing file processing unit, used for performing character conversion processing on the parsing file to obtain a data stream corresponding to the current image;

[0141] A picture display data determination unit, used to establish a picture object and set the data stream corresponding to the current picture as picture display data of the picture object;

[0142] A picture parameter determination unit, used to set picture parameters of the picture object based on the target configuration parameters;

[0143] A target picture data stream determining unit, configured to draw a picture based on the picture display data and the picture parameters, and convert the drawn picture into a data stream in a first picture format to obtain a data stream corresponding to the target picture;

[0144] A target image data stream storage unit is used to establish a target storage object and store the data stream corresponding to the target image in the target storage object;

[0145] A target storage object calling unit, configured to call the object opening interface to obtain a data stream corresponding to the target image if the current interface supports the object opening interface corresponding to the target storage object;

[0146] A target image downloading unit, used to download the target image based on the download address and image name in the target configuration parameters;

[0147] A download tag configuration unit, used to create a download tag corresponding to the target storage object if the current interface does not support the object opening interface corresponding to the target storage object, and configure the download path and image name in the download tag;

[0148] The target image downloading unit is also used to trigger a click event corresponding to the download tag to trigger and execute the download tag to download the target image.

[0149] In an optional embodiment, the device further includes:

[0150] The address information matching module is used to obtain the current address information of the current interface and match the current address information with the target address information;

[0151] A format conversion button providing module is used to provide a format conversion button to the current interface if the current address information matches the target address information, and set the format conversion button to a non-triggerable state;

[0152] The picture format determination module is used to obtain the current document object model and determine the picture format corresponding to the current picture in the current document object model;

[0153] The button state setting module is used to set the format conversion button to a triggerable state if the image format is the second image format.

[0154] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0155] The image format conversion device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0156] The embodiment of the present invention also provides a computer device having the above Figure 7 The picture format conversion device shown.

[0157] See also Figure 8 , Figure 8is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 8 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8 A processor 10 is taken as an example.

[0158] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0159] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0160] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0161] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0162] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0163] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0164] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0165] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the present invention.

Claims

1. A method for converting picture format, characterized in that: The method comprises: In response to the triggering of the format conversion button, the target configuration parameters corresponding to the current picture in the current document object model are obtained; the target configuration parameters are picture parameters of the target picture obtained by converting the current picture; the picture format of the target picture is the first picture format; Performing data processing and label matching on the picture data of the current picture to obtain a parsing file corresponding to the current picture; the parsing file includes the picture data of the current picture and a plurality of label information; Based on the target configuration parameters and the parsed file, a picture in the first picture format is generated and downloaded to obtain the target picture.

2. The method according to claim 1, characterized in that The step of obtaining target configuration parameters corresponding to the current image in the current document object model in response to the triggering of the format conversion button includes: In response to the triggering of the format conversion button, a parameter configuration interface is displayed on the current interface; the parameter configuration interface is used to provide an interactive interface for inputting configuration parameters; In response to the interaction with the parameter configuration interface, the configuration parameters input in the parameter configuration interface are acquired, and the input configuration parameters are used as the target configuration parameters.

3. The method according to claim 1, characterized in that The performing data processing and label matching on the picture data of the current picture to obtain a parsed file corresponding to the current picture includes: Adding file header information and attribute information corresponding to the parsed file to the data of the current image to obtain an initial parsed file; Call the style sheet access interface to obtain the style sheet of the current interface; Matching the font values ​​in the style sheet to obtain font tag information corresponding to the current image; Matching the style in the current image with the style in the style sheet to obtain style tag information corresponding to the current image; Acquire each picture element in the current picture and address information of each picture element, and acquire a data stream corresponding to the picture element based on the address information of the picture element; The font tag information and the style tag information are written into the tag of the initial parsed file, and the address information of the picture element is replaced with the data stream corresponding to the picture element to obtain the parsed file.

4. The method according to claim 3, characterized in that: The matching of the font values ​​in the style sheet to determine the font tag information corresponding to the current image includes: If the font value includes the first target value, using the font value as the font tag information; If the font value includes the second target value, the type information and the font information corresponding to the font value are determined, and the type information and the font information are used as the font tag information.

5. The method according to claim 3, characterized in that: The step of matching the style in the current image with the style in the style sheet to obtain style tag information corresponding to the current image includes: If the target style in the style sheet matches the style in the current picture, the target style is used as the style tag information.

6. The method according to claim 1, characterized in that The step of generating and downloading a picture in the first picture format based on the target configuration parameter and the parsed file to obtain the target picture includes: Performing character conversion processing on the parsed file to obtain a data stream corresponding to the current image; Create a picture object, and set the data stream corresponding to the current picture as the picture display data of the picture object; Based on the target configuration parameters, setting picture parameters of the picture object; Based on the picture display data and the picture parameters, draw a picture, and convert the drawn picture into a data stream in the first picture format to obtain a data stream corresponding to the target picture; Establishing the target storage object, and storing the data stream corresponding to the target image in the target storage object; If the current interface supports the object opening interface corresponding to the target storage object, the object opening interface is called to obtain the data stream corresponding to the target image; Download the target image based on the download address and image name in the target configuration parameters; If the current interface does not support the object opening interface corresponding to the target storage object, then creating a download tag corresponding to the target storage object, and configuring the download path and the picture name in the download tag; A click event corresponding to the download tag is triggered to trigger and execute the download tag, and the target image is downloaded.

7. The method according to claim 1, characterized in that The method further comprises: Obtaining current address information of the current interface, and matching the current address information with the target address information; If the current address information matches the target address information, providing the format conversion button to the current interface and setting the format conversion button to a non-triggerable state; Obtaining a current document object model, and determining a picture format corresponding to the current picture in the current document object model; If the picture format is the second picture format, the format conversion button is set to a triggerable state.

8. A picture format conversion device, characterized in that: The device comprises: A configuration parameter acquisition module, configured to acquire target configuration parameters corresponding to a current image in a current document object model in response to a trigger of a format conversion button; the target configuration parameters are image parameters of a target image obtained by converting the current image; the image format of the target image is a first image format; A parsing file acquisition module, used to perform data processing and label matching on the image data of the current image to obtain a parsing file corresponding to the current image; the parsing file includes the image data of the current image and multiple label information; A target image generation module is used to generate and download an image in the first image format based on the target configuration parameters and the parsed file to obtain the target image.

9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the image format conversion method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the image format conversion method according to any one of claims 1 to 7.