CN110688116A - Image file analysis method, device, equipment and readable medium - Google Patents

Image file analysis method, device, equipment and readable medium Download PDF

Info

Publication number
CN110688116A
CN110688116A CN201910936256.6A CN201910936256A CN110688116A CN 110688116 A CN110688116 A CN 110688116A CN 201910936256 A CN201910936256 A CN 201910936256A CN 110688116 A CN110688116 A CN 110688116A
Authority
CN
China
Prior art keywords
image file
path
attribute
image
current image
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910936256.6A
Other languages
Chinese (zh)
Inventor
李杰泓
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN201910936256.6A priority Critical patent/CN110688116A/en
Publication of CN110688116A publication Critical patent/CN110688116A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • User Interface Of Digital Computer (AREA)

Abstract

The embodiment of the disclosure discloses an image element analysis method, an image element analysis device, image element analysis equipment and a readable medium. Wherein, the method comprises the following steps: traversing image elements contained in the image file to be analyzed; if the current image element is the top-level element, extracting the top-level display parameter of the current image element as an analysis result; and if the current image element is a non-top-level element, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result. According to the technical scheme provided by the embodiment of the disclosure, the top layer display parameters of the top layer elements and the path attributes and the style attributes of the non-top layer elements under the path types are respectively extracted as analysis results, a front-end user does not need to manually screen and extract data in the image file, automatic analysis of the image file to be analyzed is realized, and the workload of file analysis is reduced; meanwhile, the accuracy of the file analysis result is improved by extracting the path attribute and the style attribute of the non-top-level element under the path type.

Description

Image file analysis method, device, equipment and readable medium
Technical Field
The embodiment of the disclosure relates to information processing technologies, and in particular, to an image file parsing method, an image file parsing device, an image file parsing apparatus, and a readable medium.
Background
With the rapid development of internet technology, the design requirements for network Graphics pages in various application programs are higher and higher, and at this time, various display pages can be designed through image codes corresponding to a Scalable Vector Graphics (SVG) format.
At present, certain front end projects need to be converted into an accessible data structure before accessing an SVG image which is previously made by a designer, at the moment, a front end programmer opens an SVG image file to be accessed through a text editor, internal source codes of the SVG image are checked, SVG image data are manually screened and extracted, SVG image data under the accessible data structure are obtained, automatic conversion can not be carried out on an access structure of the SVG image, and the manual processing amount of the front end projects before accessing the SVG image is greatly increased.
Disclosure of Invention
In view of this, the embodiments of the present disclosure provide an image file parsing method, an image file parsing device, an image file parsing apparatus, and a readable medium, which implement automatic parsing of an image file and reduce workload of file parsing.
In a first aspect, an embodiment of the present disclosure provides an image file parsing method, where the method includes:
traversing image elements contained in the image file to be analyzed;
if the current image element is the top-level element, extracting the top-level display parameter of the current image element as an analysis result;
and if the current image element is a non-top-level element, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result.
In a second aspect, an embodiment of the present disclosure provides an apparatus for parsing an image file, where the apparatus includes:
the element traversing module is used for traversing image elements contained in the image file to be analyzed;
the top-level element analysis module is used for extracting the top-level display parameter of the current image element as an analysis result if the current image element is the top-level element;
and the non-top-level element analysis module is used for extracting the path attribute and the style attribute of the current image element under the path type as an analysis result if the current image element is a non-top-level element.
In a third aspect, an embodiment of the present disclosure further provides an apparatus, where the apparatus includes:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of parsing an image file as described in any embodiment of the disclosure.
In a fourth aspect, embodiments of the present disclosure provide a readable medium, on which a computer program is stored, which when executed by a processor, implements a method for parsing an image file as described in any of the embodiments of the present disclosure.
According to the method, the device, the equipment and the readable medium for analyzing the image file, the top layer display parameters of the top layer elements and the path attributes and the style attributes of the non-top layer elements under the path types are respectively extracted as analysis results by traversing the image elements contained in the image file to be analyzed, a front-end user does not need to manually screen and extract data in the image file, automatic analysis of the image file to be analyzed is realized, and the workload of file analysis is reduced; meanwhile, the accuracy of the file analysis result is improved by extracting the path attribute and the style attribute of the non-top-level element under the path type.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
Fig. 1 shows a flowchart of a parsing method of an image file provided by an embodiment of the present disclosure;
FIG. 2 shows a schematic structural diagram of an image file to be parsed in the method provided by the embodiment of the present disclosure;
FIG. 3A is a flow chart illustrating a method for parsing non-top-level elements in the method provided by the embodiment of the disclosure;
FIG. 3B illustrates an exemplary diagram of a rectangular element in a method provided by an embodiment of the disclosure;
FIG. 4 is a flow chart illustrating another method for parsing an image file according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram illustrating an apparatus for parsing an image file according to an embodiment of the present disclosure;
fig. 6 shows a schematic structural diagram of an apparatus provided by an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise. The names of messages or information exchanged between multiple parties in the embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
Fig. 1 shows a flowchart of an image file parsing method provided by an embodiment of the present disclosure, which is applicable to any situation where a front-end application parses an image file. The method for parsing an image file provided by the embodiment of the present disclosure may be implemented by an apparatus for parsing an image file provided by the embodiment of the present disclosure, where the apparatus may be implemented in a software and/or hardware manner and integrated into a device for implementing the method, and the device for implementing the method in the embodiment of the present disclosure may be an intelligent terminal such as a mobile phone, a tablet, or a Personal Digital Assistant (PDA).
Specifically, as shown in fig. 1, the method for parsing an image file provided in the embodiment of the present disclosure may include the following steps:
s110, traversing image elements contained in the image file to be analyzed.
Specifically, in the embodiment of the present disclosure, mainly aiming at the problem that each element data in an image file needs to be artificially screened and extracted, all image elements included in the image file to be analyzed are automatically analyzed; the image file to be analyzed is an image which is stored in a certain specific image storage format and has an analysis requirement on the image file by a front-end application so as to be displayed in an application webpage or modify a display style, and the image file to be analyzed in the embodiment of the disclosure can be an SVG file which provides three types of graphic objects: vector graphics (such as paths consisting of straight lines and curves), images and text, rendering SVG image files directly through code written in the SVG format language; in this case, if the image file is used as an image container, the image element refers to an object having a different graphics function or an overall description function constituting the image file, that is, a vector graphic of a different shape contained in the image container, or a container function object that summarizes all vector graphics collectively.
Optionally, when the image file to be analyzed is obtained, the image file to be analyzed first needs to be correspondingly analyzed to obtain all image elements contained in the image file, and in order to ensure the integrity of the analysis result, each image element contained in the image file to be analyzed needs to be traversed according to a specific sequence, so that the attribute information of each image element is analyzed and extracted subsequently, and thus the analysis result corresponding to the whole image file to be analyzed is obtained.
S120, judging whether the current image element is a top-level element, if so, executing S130; if not, go to S140.
The top layer element refers to an object wrapped by the outermost layer of the image file to be parsed and describing the overall functional characteristics of the image file to be parsed, and includes sub-elements in various different graphic shapes, as shown in fig. 2.
Specifically, because different types of image elements have different display information in the image file, when traversing the image elements included in the image file to be analyzed, the embodiment of the present disclosure needs to determine the type of each image element, that is, determine whether the current image element is a top-level element for each image element; illustratively, the code format of an SVG image file may be roughly as follows:
Figure BDA0002221671360000061
at the moment, < SVG > and < root > are top-level element tags in the SVG image file, and < rect > and < line > are non-top-level element tags in the image file; in the embodiment of the disclosure, by reading the code content in the image file to be analyzed and judging whether the current image element is a top-layer element according to the element label of the package corresponding to each image element, different operations are subsequently adopted to analyze different types of image elements.
S130, extracting the top layer display parameter of the current image element as an analysis result.
Specifically, when an image file is written, the whole functional characteristics of the image file are described by the top-level element, for example, if the image file is displayed in a web page, information such as an interception display area and a display window size of the image file to be displayed; therefore, in the embodiment of the present disclosure, when traversing the image elements included in the image file to be analyzed, if the current image element is a top-level element, the whole characteristic information of the image file, which is described by the top-level element in the image file to be analyzed, that is, the top-level display parameter in the embodiment of the present disclosure is directly read in the image file to be analyzed, and the top-level display parameter is used as the analysis result of the image file to be analyzed, and is used for indicating information such as a specific display area and a display window size of the image file to be analyzed when the image file to be analyzed is displayed in a web page.
Illustratively, the top-level display parameter in the embodiment of the present disclosure may be a viewBox parameter in an SVG image file, where the viewBox may be represented by "x, y, width, height", where x represents an abscissa of an upper left corner of an area that needs to be displayed in a viewport in an image file to be analyzed, y represents an ordinate of an upper left corner of the area that needs to be displayed in the viewport, width represents an area width displayed in the viewport, and height represents an area height displayed in the viewport; in the embodiment of the present disclosure, the area specified by the viewBox parameter is displayed in the corresponding web page.
In addition, in order to ensure the display accuracy of the image file to be analyzed, after the top-level display parameters are extracted, the embodiment of the disclosure may further include: and taking the top layer display parameters as the display parameters of the image file to be analyzed.
Specifically, because the top-level element in the image file to be analyzed is used for describing the overall display characteristics of the image file, the top-level display parameter corresponding to the top-level element can be used as the display parameter of the image file to be analyzed, so that the image file to be analyzed can be displayed in the subsequent webpage directly according to the information such as the display area, the display size and the like of the image file to be analyzed, which is set in the top-level display parameter.
And S140, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result.
Specifically, the non-top layer elements in the image file to be analyzed refer to various different graphic elements contained under the top layer elements, such as various graphs, such as rectangles, lines, ellipses, polygons, and the like, and the non-top layer elements in the embodiment of the present disclosure are mainly used for describing various special effect graphs contained in the image file to be analyzed; therefore, when traversing the image elements contained in the image file to be analyzed, if the current image element is a non-top-level element, the embodiment of the present disclosure needs to acquire attribute information such as graphic description and display style of the current image element, since the image file may describe attribute information of image elements by different element types, to create image elements of various different shapes, in order to quickly and accurately obtain the attribute information of the image elements, the disclosed embodiments try to describe each image element by using a preset path (path) element, the shape of the path element may be defined by a corresponding path command attribute, which is a sequence of "command + argument", each command may be represented by a key, if the 'M' indicates a 'Move to' command, the command is used for moving a certain point, and the parameter after the command indicates the horizontal and vertical coordinates of the point moved at this time; different commands correspond to different drawing operations, and different shapes can be drawn by combining a plurality of commands; in addition, the path element may describe style information of the element by different attributes, such as filling colors of different graphic elements.
At this time, when acquiring attribute information of a current image element, the embodiment of the present disclosure first needs to determine an element type of the current image element to convert the current image element in the non-path type into a corresponding path type, and then extracts a corresponding path attribute and a corresponding style attribute directly according to a path command attribute of the current image element in the path type, where the path attribute and the style attribute are used as an analysis result of a non-top-level element in an image file to be analyzed and are used to indicate a shape and style information of the non-top-level element in the image file to be analyzed.
For example, the path attribute in the embodiment of the present disclosure may be "command + parameter" information of the current image element in the path command attribute, and the style attribute is rendering information preset for each image element in the image file to be parsed, such as a file parameter, a file-rule parameter, a stroke-line parameter, a stroke-width parameter, a file-option parameter, a stroke-option parameter, a transform parameter, and the like, where the file parameter indicates a color that needs to be filled in the image element.
In addition, since the image file to be parsed may include a plurality of non-top-level elements, in order to store the path attribute and the style attribute of each non-top-level element one by one, after extracting the path attribute and the style attribute of the current image element in the path type, the embodiment of the present disclosure may further include: and storing the path attribute into a preset path array, and storing the style attribute into a preset style array.
Specifically, when image elements contained in the image file to be analyzed are traversed, the path attributes and the style attributes of the current image elements under the path types can be sequentially and respectively stored through the preset path array and the preset style array according to the traversal sequence, the path attributes and the style attributes stored in the path array and the style array are ensured to be in one-to-one correspondence, and the accuracy of the analysis result of each image element is improved.
According to the technical scheme provided by the embodiment of the disclosure, the top layer display parameters of the top layer elements and the path attributes and the style attributes of the non-top layer elements under the path types are respectively extracted as analysis results by traversing the image elements contained in the image file to be analyzed, a front-end user does not need to manually screen and extract data in the image file, the automatic analysis of the image file to be analyzed is realized, and the workload of file analysis is reduced; meanwhile, the accuracy of the file analysis result is improved by extracting the path attribute and the style attribute of the non-top-level element under the path type.
On the basis of the technical solutions provided by the above embodiments, specific parsing processes for non-top-level elements of different types in the parsing method for image files provided by the embodiments of the present disclosure are further described. As shown in fig. 3A, in the method for parsing an image file, extracting a path attribute and a style attribute of the current image element under the path type as a parsing result may specifically include:
s310, if the current image element is a non-top-level element, judging whether the current image element is a path type, if so, executing S320; if not, go to S330.
Specifically, because the non-top-level element describes the corresponding attribute information through different element types, and the path type can ensure that various attribute information of the image element can be quickly and accurately acquired, when it is determined that the current image element is the non-top-level element, the embodiment of the present disclosure first determines whether the current image element is the path type, and then executes the following corresponding operation according to different element types, so as to quickly and accurately acquire the attribute information of the non-top-level element.
S320, directly extracting the path attribute and the style attribute of the current image element as an analysis result.
Optionally, if the current image element is of the path type, at this time, the current image element is already described by the path command attribute corresponding to the path type, so that the embodiment of the present disclosure may directly extract the corresponding path attribute and the style attribute as the analysis result according to the path command attribute of the current image element.
S330, according to the matching relation between the image description attribute of the current image element and the preset path command, performing path type conversion on the current image element, and extracting the path attribute and the style attribute of the current image element after conversion as an analysis result.
Optionally, if the current image element is of a non-path type, in order to quickly and accurately obtain attribute information of the current image element, the embodiment of the present disclosure first needs to convert the current image element into a corresponding path element; specifically, firstly, the meanings of various preset path commands and corresponding parameter writing formats are determined, for example, "M" represents a "Move to" command, parameter (x, y) represents the horizontal and vertical coordinates of a point moving this time, "L" represents a "Line to" command, parameter (x, y) represents the horizontal and vertical coordinates of a specified ending point, and the like, from the current point; and then obtaining the image description attribute of the current image element, wherein the image description information indicates the shape of the current image element and the position of the current image element in an image file to be analyzed, at the moment, the image description information of the current image element is matched with a preset path command, so that the path command used for drawing the shape of the current image element is selected from a path command set, the graphic code of the current image element is automatically written through the selected path command, and then the path type of the current image element is converted to obtain the path command information used for describing the current image element, and thus the path attribute and the style attribute of the current image element are extracted from the converted path command information to serve as an analysis result.
For example, if the current image element is a rectangle with radian corners and the current image element is of a non-path type, as shown in fig. 3B, the rectangle needs to be converted into a corresponding path type, and the attributes of the rectangle element include: the method comprises the following steps that when a vertex angle of a rectangle does not have a radian, corresponding upper left vertex angle coordinates (x, y), the width and the height (w, h) of the rectangle, and horizontal and vertical corner radiuses (rx, ry) corresponding to the radian of the vertex angle of the rectangle are obtained; it can be determined that the rectangular element is composed of 4 straight lines and 4 arc lines in a closed manner, so that in the path command set, first the move command "M", the draw straight line command "L", the draw arc command "a" and the path close command "Z" are selected, the path starting point of the rectangular element is first moved to (x + rx, y) by the command "M", then a straight line is drawn from point (x + rx, y) to point (x + w-rx, y) by the draw straight line command "L", an arc line is drawn from point (x + w-rx, y) to point (x + w, y + ry) by the draw arc command "a", a straight line is drawn from point (x + w, y + h-ry) to point (x + w, y + h-ry) by the draw straight line command "L", an arc line is drawn from point (x + w, y + h-ry) to point (x + w-rx, y + h), continuing to draw a straight line from the point (x + w-rx, y + h) to the point (x + rx, y + h) through the straight line drawing command 'L', continuing to draw an arc from the point (x + rx, y + h) to the point (x, y + h-ry) through the arc drawing command 'A', continuing to draw a straight line from the point (x, y + h-ry) to the point (x, y + ry) through the straight line drawing command 'L', continuing to draw an arc from the point (x, y + ry) to the point (x + rx, y) through the arc drawing command 'A', and finally using the path closing command 'Z' at the point (x + rx, y) to form a corresponding rectangular style element and correspondingly convert the original attribute.
It should be noted that, in the embodiment of the present disclosure, for image elements with different shapes, such as a circle, an ellipse, a polyline, and the like, the image description attribute of the image element and the preset path command may be matched through the similar processes, so as to perform automatic conversion under a path type on an image element with a non-path type, improve the automation of image file analysis, and reduce the workload of manual image file analysis.
Fig. 4 is a flowchart illustrating another parsing method for an image file according to an embodiment of the present disclosure, which is optimized based on the alternatives provided in the foregoing embodiments. Specifically, the present embodiment mainly introduces the detailed parsing process of the image file to be parsed.
Optionally, as shown in fig. 4, the method in the embodiment of the present disclosure may include the following steps:
s410, setting a corresponding top-layer element label according to the reading content of the image file to be analyzed.
Optionally, before analyzing the element attribute information of the image file to be analyzed, in order to clearly distinguish a top-level element from a non-top-level element in the image file to be analyzed and ensure accuracy of an analysis result, in the embodiment of the present disclosure, first, specific content of the image file to be analyzed needs to be read, a tag existing in the image file to be analyzed is found out, and a corresponding top-level element tag is set for the top-level element, so that the top-level element and the non-top-level element are clearly distinguished in the following.
For example, in the embodiment of the present disclosure, content in an image file to be parsed may be read through an fs.readfile function in a file parser, the image file to be parsed is read in a character string form, then a < docType > tag that has been set in the read character string is deleted, and a < root > </root > tag is wrapped in an outermost position of the character string to serve as a top-level element tag.
S420, if the updated image file to be analyzed is legal, constructing an element node tree of the image file to be analyzed according to the top element label and the non-top element attribute under the top element label.
Specifically, after the corresponding top-level element tag is reset for the image file to be parsed, it is required to verify whether the updated image file to be parsed is legal, that is, whether an error exists in the code of the updated image file to be parsed is judged, if the updated image file to be parsed is legal, the read code of the updated image file to be parsed is traversed, and an element node tree of the image file to be parsed is constructed according to the top-level element tag and attribute information of various different graphic elements (non-top-level elements in the embodiment of the present disclosure) included under the top-level element tag, such as a hierarchical relationship between non-top-level elements, where a root node in the element node tree is a top-level element and child nodes are non-top-level elements under different hierarchies.
And S430, traversing the top-level element and the non-top-level element in the image file to be analyzed according to the element node tree.
Optionally, in order to ensure the traversal integrity of the image elements in the image file to be analyzed, the embodiment of the present disclosure may traverse each element node in a pre-constructed element node tree according to different set orders, so as to sequentially obtain a top-level element and a non-top-level element in the image file to be analyzed; may include first order traversal, middle order traversal, and next order traversal, etc.; illustratively, starting from a root node in an element node tree, traversing corresponding subtrees from left to right in sequence to obtain top-level elements and all non-top-level elements contained in an image file to be analyzed, and ensuring the integrity of element traversal.
S440, judging whether the current image element is a top-level element, if so, executing S450; if not, go to S460.
S450, extracting the top layer display parameter of the current image element as an analysis result.
And S460, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result.
And S470, executing corresponding display or update operation on the image file to be analyzed according to the analysis result.
Optionally, after the analysis result of the image file to be analyzed is obtained, if the image file to be analyzed needs to be displayed in the webpage, a corresponding display area is directly determined in the image file to be analyzed according to the top-layer display parameters, a corresponding display position in the webpage is determined according to the path attribute of the non-top-layer element, a corresponding display style in the webpage is determined according to the style attribute of the non-top-layer element, and then the complete image file to be analyzed is displayed in the webpage; or if the drawing position or the style of a certain non-top-level element in the image file to be analyzed needs to be updated, the path attribute or the style attribute of the non-top-level element can be directly modified, so that the shape, the position or the style of each image element contained in the image file to be analyzed can be quickly updated.
According to the technical scheme provided by the embodiment of the disclosure, the traversal integrity of the image elements is ensured by traversing the top layer elements and the non-top layer elements contained in the image file to be analyzed through the pre-constructed element node tree, and then the top layer display parameters of the top layer elements and the path attributes and the style attributes of the non-top layer elements under the path types are respectively extracted as analysis results, so that the data in the image file to be analyzed are not required to be manually screened and extracted by a front-end user, the automatic analysis of the image file to be analyzed is realized, the workload of file analysis is reduced, and the accuracy of the file analysis results is improved; meanwhile, according to the top-layer display parameters, the path attributes and the style attributes, corresponding display or update operations can be rapidly executed on the image file to be analyzed, and the processing efficiency of the image file is improved.
Fig. 5 is a schematic structural diagram of an image file parsing apparatus provided by an embodiment of the present disclosure, where the embodiment of the present disclosure is applicable to any situation where a front-end application parses an image file, and the apparatus may be implemented by software and/or hardware and integrated in a device executing the method. As shown in fig. 5, the apparatus for parsing an image file in the embodiment of the present disclosure may include:
an element traversing module 510, configured to traverse image elements included in an image file to be parsed;
a top-level element parsing module 520, configured to, if a current image element is a top-level element, extract a top-level display parameter of the current image element as a parsing result;
a non-top-level element parsing module 530, configured to, if the current image element is a non-top-level element, extract a path attribute and a style attribute of the current image element under the path type as a parsing result.
According to the technical scheme provided by the embodiment of the disclosure, the top layer display parameters of the top layer elements and the path attributes and the style attributes of the non-top layer elements under the path types are respectively extracted as analysis results by traversing the image elements contained in the image file to be analyzed, a front-end user does not need to manually screen and extract data in the image file, the automatic analysis of the image file to be analyzed is realized, and the workload of file analysis is reduced; meanwhile, the accuracy of the file analysis result is improved by extracting the path attribute and the style attribute of the non-top-level element under the path type.
Further, the non-top element parsing module 530 may be specifically configured to:
if the current image element is of the path type, directly extracting the path attribute and the style attribute of the current image element as an analysis result;
if the current image element is of a non-path type, performing path type conversion on the current image element according to the matching relationship between the image description attribute of the current image element and a preset path command, and extracting the path attribute and the style attribute of the converted current image element as an analysis result.
Further, the apparatus for analyzing an image file may further include:
and the file parameter determining module is used for taking the top layer display parameters as the display parameters of the image file to be analyzed.
Further, the apparatus for analyzing an image file may further include:
and the storage module is used for storing the path attribute into a preset path array and storing the style attribute into a preset style array.
Further, the apparatus for analyzing an image file may further include:
the label setting module is used for setting a corresponding top-layer element label according to the read content of the image file to be analyzed;
and the node tree construction module is used for constructing an element node tree of the image file to be analyzed according to the top element label and the non-top element attribute under the top element label if the updated image file to be analyzed is legal.
Further, the element traversing module 510 may be specifically configured to:
and traversing top-level elements and non-top-level elements in the image file to be analyzed according to the element node tree.
Further, the apparatus for analyzing an image file may further include:
and the operation execution module is used for executing corresponding display or update operation on the image file to be analyzed according to the analysis result.
Further, the image file to be analyzed is a Scalable Vector Graphics (SVG) file.
The image file parsing device provided by the embodiment of the present disclosure is the same as the image file parsing method provided by the above embodiment, and technical details that are not described in detail in the embodiment of the present disclosure may be referred to the above embodiment, and the embodiment of the present disclosure has the same beneficial effects as the above embodiment.
Referring now to FIG. 6, a block diagram of an apparatus 600 suitable for use in implementing embodiments of the present disclosure is shown. The devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., car navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. The device shown in fig. 6 is only an example and should not bring any limitation to the function and use range of the embodiments of the present disclosure.
As shown in fig. 6, the apparatus 600 may include a processing device (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage device 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an apparatus 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some implementations, the devices may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the apparatus; or may be separate and not incorporated into the device.
The computer readable medium carries one or more programs which, when executed by the apparatus, cause the apparatus to: traversing image elements contained in the image file to be analyzed; if the current image element is the top-level element, extracting the top-level display parameter of the current image element as an analysis result; and if the current image element is a non-top-level element, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
According to one or more embodiments of the present disclosure, there is provided an image file parsing method, including:
traversing image elements contained in the image file to be analyzed;
if the current image element is the top-level element, extracting the top-level display parameter of the current image element as an analysis result;
and if the current image element is a non-top-level element, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result.
According to one or more embodiments of the present disclosure, in the foregoing method, the extracting, as an analysis result, a path attribute and a style attribute of the current image element under the path type includes:
if the current image element is of the path type, directly extracting the path attribute and the style attribute of the current image element as an analysis result;
if the current image element is of a non-path type, performing path type conversion on the current image element according to the matching relationship between the image description attribute of the current image element and a preset path command, and extracting the path attribute and the style attribute of the converted current image element as an analysis result.
According to one or more embodiments of the present disclosure, the method, after extracting a top-level display parameter of the current image element as an analysis result, further includes:
and taking the top layer display parameters as the display parameters of the image file to be analyzed.
According to one or more embodiments of the present disclosure, the method, after extracting a path attribute and a style attribute of the current image element under a path type as a parsing result, further includes:
and storing the path attribute into a preset path array, and storing the style attribute into a preset style array.
According to one or more embodiments of the present disclosure, the method further includes:
setting a corresponding top-layer element label according to the read content of the image file to be analyzed;
and if the updated image file to be analyzed is legal, constructing an element node tree of the image file to be analyzed according to the top element label and the non-top element attribute under the top element label.
According to one or more embodiments of the present disclosure, in the foregoing method, the traversing image elements included in an image file to be parsed includes:
and traversing top-level elements and non-top-level elements in the image file to be analyzed according to the element node tree.
According to one or more embodiments of the present disclosure, the method further includes:
and executing corresponding display or update operation on the image file to be analyzed according to the analysis result.
According to one or more embodiments of the disclosure, in the above method, the image file to be parsed is a scalable vector graphics SVG file.
According to one or more embodiments of the present disclosure, there is provided an apparatus for parsing an image file, the apparatus including:
the element traversing module is used for traversing image elements contained in the image file to be analyzed;
the top-level element analysis module is used for extracting the top-level display parameter of the current image element as an analysis result if the current image element is the top-level element;
and the non-top-level element analysis module is used for extracting the path attribute and the style attribute of the current image element under the path type as an analysis result if the current image element is a non-top-level element.
According to one or more embodiments of the present disclosure, in the apparatus, the non-top-level element parsing module is specifically configured to:
if the current image element is of the path type, directly extracting the path attribute and the style attribute of the current image element as an analysis result;
if the current image element is of a non-path type, performing path type conversion on the current image element according to the matching relationship between the image description attribute of the current image element and a preset path command, and extracting the path attribute and the style attribute of the converted current image element as an analysis result.
According to one or more embodiments of the present disclosure, the above apparatus further includes:
and the file parameter determining module is used for taking the top layer display parameters as the display parameters of the image file to be analyzed.
According to one or more embodiments of the present disclosure, the above apparatus further includes:
and the storage module is used for storing the path attribute into a preset path array and storing the style attribute into a preset style array.
According to one or more embodiments of the present disclosure, the above apparatus further includes:
the label setting module is used for setting a corresponding top-layer element label according to the read content of the image file to be analyzed;
and the node tree construction module is used for constructing an element node tree of the image file to be analyzed according to the top element label and the non-top element attribute under the top element label if the updated image file to be analyzed is legal.
According to one or more embodiments of the present disclosure, in the apparatus, the element traversal module is specifically configured to:
and traversing top-level elements and non-top-level elements in the image file to be analyzed according to the element node tree.
According to one or more embodiments of the present disclosure, the above apparatus further includes:
and the operation execution module is used for executing corresponding display or update operation on the image file to be analyzed according to the analysis result.
According to one or more embodiments of the disclosure, in the above apparatus, the image file to be parsed is a scalable vector graphics SVG file.
In accordance with one or more embodiments of the present disclosure, there is provided an apparatus comprising:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of parsing an image file as described in any embodiment of the disclosure.
According to one or more embodiments of the present disclosure, a readable medium is provided, on which a computer program is stored, which when executed by a processor, implements a parsing method of an image file as described in any of the embodiments of the present disclosure.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (11)

1. An image file parsing method, comprising:
traversing image elements contained in the image file to be analyzed;
if the current image element is the top-level element, extracting the top-level display parameter of the current image element as an analysis result;
and if the current image element is a non-top-level element, extracting the path attribute and the style attribute of the current image element under the path type as an analysis result.
2. The method of claim 1, wherein the extracting, as a result of the parsing, a path attribute and a style attribute of the current image element under a path type comprises:
if the current image element is of the path type, directly extracting the path attribute and the style attribute of the current image element as an analysis result;
if the current image element is of a non-path type, performing path type conversion on the current image element according to the matching relationship between the image description attribute of the current image element and a preset path command, and extracting the path attribute and the style attribute of the converted current image element as an analysis result.
3. The method of claim 1, further comprising, after extracting top-level display parameters of the current image element as a parsing result:
and taking the top layer display parameters as the display parameters of the image file to be analyzed.
4. The method of claim 1, further comprising, after extracting a path attribute and a style attribute of the current image element under the path type as a parsing result:
and storing the path attribute into a preset path array, and storing the style attribute into a preset style array.
5. The method of claim 1, further comprising:
setting a corresponding top-layer element label according to the read content of the image file to be analyzed;
and if the updated image file to be analyzed is legal, constructing an element node tree of the image file to be analyzed according to the top element label and the non-top element attribute under the top element label.
6. The method of claim 5, wherein traversing image elements contained in the image file to be parsed comprises:
and traversing top-level elements and non-top-level elements in the image file to be analyzed according to the element node tree.
7. The method of claim 1, further comprising:
and executing corresponding display or update operation on the image file to be analyzed according to the analysis result.
8. The method according to any one of claims 1-7, wherein the image file to be parsed is a Scalable Vector Graphics (SVG) file.
9. An apparatus for parsing an image file, comprising:
the element traversing module is used for traversing image elements contained in the image file to be analyzed;
the top-level element analysis module is used for extracting the top-level display parameter of the current image element as an analysis result if the current image element is the top-level element;
and the non-top-level element analysis module is used for extracting the path attribute and the style attribute of the current image element under the path type as an analysis result if the current image element is a non-top-level element.
10. An apparatus, characterized in that the apparatus comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of parsing an image file as recited in any of claims 1-8.
11. A readable medium, on which a computer program is stored which, when being executed by a processor, carries out a method for parsing an image file according to any one of claims 1 to 8.
CN201910936256.6A 2019-09-29 2019-09-29 Image file analysis method, device, equipment and readable medium Pending CN110688116A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910936256.6A CN110688116A (en) 2019-09-29 2019-09-29 Image file analysis method, device, equipment and readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910936256.6A CN110688116A (en) 2019-09-29 2019-09-29 Image file analysis method, device, equipment and readable medium

Publications (1)

Publication Number Publication Date
CN110688116A true CN110688116A (en) 2020-01-14

Family

ID=69111179

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910936256.6A Pending CN110688116A (en) 2019-09-29 2019-09-29 Image file analysis method, device, equipment and readable medium

Country Status (1)

Country Link
CN (1) CN110688116A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111324351A (en) * 2020-02-19 2020-06-23 网易(杭州)网络有限公司 File processing method and device, computer readable medium and electronic equipment
CN111897989A (en) * 2020-07-29 2020-11-06 北京字节跳动网络技术有限公司 Image processing method and device, terminal and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107221016A (en) * 2016-03-22 2017-09-29 阿里巴巴集团控股有限公司 The processing method and its device of the Path figures of SVG forms
CN107291476A (en) * 2017-06-27 2017-10-24 北京微影时代科技有限公司 Canvas code generating methods, device, electronic equipment and storage medium
US20180173683A1 (en) * 2016-12-15 2018-06-21 Sap Se Graphics display capture system
US20190004778A1 (en) * 2017-06-30 2019-01-03 Samsung Electronics Co., Ltd. Method and electronic device for rendering scalable vector graphics content
CN109445778A (en) * 2018-09-13 2019-03-08 珠海豆饭科技有限公司 A kind of method and apparatus that the interface auxiliary based on SVG file generates

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107221016A (en) * 2016-03-22 2017-09-29 阿里巴巴集团控股有限公司 The processing method and its device of the Path figures of SVG forms
US20180173683A1 (en) * 2016-12-15 2018-06-21 Sap Se Graphics display capture system
CN107291476A (en) * 2017-06-27 2017-10-24 北京微影时代科技有限公司 Canvas code generating methods, device, electronic equipment and storage medium
US20190004778A1 (en) * 2017-06-30 2019-01-03 Samsung Electronics Co., Ltd. Method and electronic device for rendering scalable vector graphics content
CN109445778A (en) * 2018-09-13 2019-03-08 珠海豆饭科技有限公司 A kind of method and apparatus that the interface auxiliary based on SVG file generates

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111324351A (en) * 2020-02-19 2020-06-23 网易(杭州)网络有限公司 File processing method and device, computer readable medium and electronic equipment
CN111324351B (en) * 2020-02-19 2024-02-23 网易(杭州)网络有限公司 File processing method, device, computer readable medium and electronic equipment
CN111897989A (en) * 2020-07-29 2020-11-06 北京字节跳动网络技术有限公司 Image processing method and device, terminal and storage medium

Similar Documents

Publication Publication Date Title
US20230394671A1 (en) Image segmentation method and apparatus, and device, and storage medium
US11875437B2 (en) Image drawing method based on target template image, apparatus, readable medium and electronic device
CN110442330A (en) List element conversion method, device, electronic equipment and storage medium
CN109558128A (en) Json data analysis method, device and computer readable storage medium
WO2022111591A1 (en) Page generation method and apparatus, storage medium, and electronic device
CN113468330B (en) Information acquisition method, device, equipment and medium
CN111857719A (en) Data processing method, device, electronic equipment and medium
CN112631588A (en) File generation method and device, electronic equipment and computer readable medium
CN110688116A (en) Image file analysis method, device, equipment and readable medium
CN115731313A (en) SVG format picture processing method, device, equipment, medium and product
CN116894188A (en) Service tag set updating method and device, medium and electronic equipment
CN114721656A (en) Interface structure extraction method, device, medium and electronic equipment
CN113797554B (en) Game engine resource processing method and device, storage medium and electronic equipment
CN111124541A (en) Configuration file generation method, device, equipment and medium
CN115268904A (en) User interface design file generation method, device, equipment and medium
US20240021004A1 (en) Cross-region document content recognition method, apparatus and medium
CN116860286A (en) Page dynamic update method, device, electronic equipment and computer readable medium
CN113312568B (en) Web information extraction method and system based on HTML source code and webpage snapshot
CN113807056A (en) Method, device and equipment for correcting error of document name sequence number
CN111008178A (en) Data processing method and device, electronic equipment and computer readable storage medium
CN111461227B (en) Sample generation method, device, electronic equipment and computer readable medium
CN117194437B (en) File storage method, device, electronic equipment and computer readable medium
CN111026983B (en) Method, device, medium and electronic equipment for realizing hyperlink
CN113760834B (en) File classification method, device, equipment and medium
CN116974684B (en) Map page layout method, map page layout device, electronic equipment and computer readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20200114