Methods, apparatus, devices and media for replacing logo images within documents
By detecting document format and adjusting logo image size to fit the placement unit, the problem of time-consuming, labor-intensive, and inconsistent manual processes in updating corporate logos has been solved, achieving automated and efficient logo replacement and improving the uniformity and aesthetics of the brand image.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-04
- Publication Date
- 2026-03-13
AI Technical Summary
In existing technologies, updating corporate logos in business documents of different formats involves time-consuming and labor-intensive manual operations that are prone to errors and make it difficult to ensure consistency, thus affecting the professionalism and standardization of the brand image.
By detecting the document format type, the corresponding parsing algorithm is used to obtain the placement unit attribute information of the logo image, and the size of the target logo image is adjusted according to this information to adapt it to the placement unit, thus achieving automatic replacement of the logo image.
It enables automated replacement of logo images, reducing manual costs, improving replacement efficiency and accuracy, and ensuring the logo's fit and aesthetics in documents.
Smart Images

Figure CN121053257B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of document processing technology, and more specifically, to a method, apparatus, device, and storage medium for replacing logo images within a document. Background Technology
[0002] In the process of modern enterprise digital operations, daily business operations generate a massive amount of electronic documents in heterogeneous formats, such as Word and Excel. These business documents not only carry the company's core business information but also serve as important windows for showcasing the company's brand image. With strategic adjustments and brand upgrades, the company logo, as the core visual identifier of the brand image, frequently needs to be changed and iterated. In practical applications, differences in logo versions within business documents can lead to inconsistencies in brand image expression, affecting the professionalism and standardization of the company's external presentation.
[0003] Currently, updating logos in business documents of different formats generally involves manual editing and replacement of each document. This method has significant technical bottlenecks: on the one hand, manual operation consumes a large amount of time and manpower when dealing with tens of thousands of documents; on the other hand, due to the diverse document formats and complex content, manual operation is prone to omissions and errors, and it is difficult to guarantee the consistency of the replacement effect. Therefore, improving the accuracy and efficiency of logo updates is an urgent problem to be solved. Summary of the Invention
[0004] In view of this, this application provides a method, apparatus, device, and storage medium for replacing logo images within a document, in order to at least solve the problems existing in the related art.
[0005] Specifically, this application is implemented through the following technical solution:
[0006] This application provides a method for replacing logo images within a document, including:
[0007] Obtain the original document and the target logo image, and detect the document format type of the original document;
[0008] Based on the document format type of the original document, the original document is parsed using a parsing algorithm corresponding to the document format type to obtain the attribute information of the placement unit corresponding to each original logo image; the placement unit is used to carry the logo image, and the attribute information includes size information;
[0009] For any original logo image, the size of the target logo image is adjusted according to the size information of the placement unit corresponding to the original logo image, so that the size of the target logo image is adapted to the size of the placement unit corresponding to the original logo image;
[0010] The original logo image is replaced with the resized target logo image to obtain the target document.
[0011] In some implementations, the document format type includes a Word document or an Excel document; the step of parsing the original document using a parsing algorithm corresponding to the document format type to obtain the attribute information of the placement unit corresponding to each original logo image includes:
[0012] If the document format type includes a Word document, the Word document parsing interface is called to parse the original document to obtain the size information of the placement unit corresponding to each original logo image; or...
[0013] If the document format type includes an Excel document, the Excel document parsing interface is called to parse the original document and obtain the size information of the placement unit corresponding to each original logo image.
[0014] In some implementations, when the document format type includes a Word document, the placement unit includes a logo container; the step of calling the Word document parsing interface to parse the original document and obtain the size information of the placement unit corresponding to each original logo image includes:
[0015] The original document is parsed by calling the Word document parsing interface to obtain the size information of at least one container corresponding to each header in the original document, and the size information of the logo container corresponding to each original logo image is determined from the size information corresponding to multiple containers respectively.
[0016] In some implementations, each container has resource attribute information; determining the size information of the logo container corresponding to each original logo image from the attribute information corresponding to multiple containers includes:
[0017] For each container, determine whether the resource attribute information of the container includes image elements;
[0018] The size information of the container corresponding to the resource attribute information of the image element is determined as the size information of the logo container corresponding to the original logo image.
[0019] In some implementations, adjusting the size of the target logo image based on the size information of the placement unit corresponding to the original logo image for any given original logo image includes:
[0020] For any given original logo image, the size of the target logo image is adjusted based on the size information of the logo container corresponding to the original logo image.
[0021] In some implementations, after replacing the original logo image with the resized target logo image to obtain the target document, the method further includes:
[0022] Obtain the identification information of the resized target logo image in the target document and the identification information of the original logo image in the target document;
[0023] The identifier information of the resized target logo image is associated with the logo container, and the logo deletion interface is called to delete the identifier information of the original logo image associated with the logo container.
[0024] In some implementations, replacing the original logo image with a resized target logo image to obtain the target document includes:
[0025] For each logo container, create a transparent canvas of the same size as the logo container;
[0026] Paste the resized target logo image into the transparent canvas to generate a new logo image, and replace the original logo image with the new logo image to obtain the target document.
[0027] In some implementations, when the document format type includes an Excel document, the placement unit includes a cell; the step of calling the Excel document parsing interface to parse the original document and obtain the size information of the placement unit corresponding to each original logo image includes:
[0028] Call the Excel document parsing interface to parse the original document and obtain the image attribute information of each image contained in at least one worksheet of the original document;
[0029] For each image, the anchor point method of the image is determined from the image attribute information corresponding to the image;
[0030] The image with a fixed anchor point is identified as the original logo image, and the size information of the cell corresponding to the original logo image in the original document is determined; wherein, a fixed anchor point means that the image is located in a cell at a preset position in the worksheet.
[0031] In some implementations, adjusting the size of the target logo image based on the size information of the placement unit corresponding to the original logo image for any given original logo image includes:
[0032] For any original logo image, calculate the physical size of the cell containing the original logo image, and adjust the size of the target logo image based on the physical size of the cell containing the original logo image.
[0033] In some implementations, calculating the physical size of the cell containing any original logo image includes:
[0034] Obtain the row and column range of each cell in the original document;
[0035] For each original logo image, determine whether the initial position of the cell containing the original logo image is within the row and column range of any target cell. If so, update the range of the cell containing the original logo image to the row and column range of the target cell.
[0036] Using a unit conversion algorithm, the range of the cell containing the original logo image is converted into pixel units to obtain the physical size of the cell containing the original logo image.
[0037] In some implementations, replacing the original logo image with a resized target logo image to obtain the target document includes:
[0038] Based on the physical size of the cell where the original logo image is located and the size information of the target logo image after size adjustment, determine the center offset of the target logo image relative to the cell;
[0039] The anchor point position is determined based on the center offset and the row and column range of the cell;
[0040] The resized target logo image is placed at the anchor point, and the original logo image is deleted to obtain the target document.
[0041] This application also provides a device for replacing logo images within a document, including:
[0042] The detection module is used to acquire the original document and the target logo image, and to detect the document format type of the original document;
[0043] The parsing module is used to parse the original document according to its document format type using a parsing algorithm corresponding to the document format type, and to obtain the attribute information of the placement unit corresponding to each original logo image; the placement unit is used to carry the logo image, and the attribute information includes size information;
[0044] The adjustment module is used to adjust the size of the target logo image based on the size information of the placement unit corresponding to the original logo image, so that the target logo image is adapted to the size of the placement unit corresponding to the original logo image;
[0045] The replacement module is used to replace the original logo image with the target logo image after resizing, to obtain the target document.
[0046] This application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the logo image replacement method in any of the foregoing embodiments.
[0047] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the logo image replacement method in any of the foregoing embodiments.
[0048] This application also provides a computer program product, including a computer program that, when run by a processor, performs steps such as the logo image replacement method in any of the possible documents described above.
[0049] The technical solutions provided by the embodiments of this application may include the following beneficial effects:
[0050] In this embodiment, the original document is type-detected, and parsing algorithm corresponding to the document format type is used to parse the original document to obtain the attribute information of the placement unit corresponding to each original logo image in the original document. Here, the placement unit is used to carry the logo image. For any original logo image, the size of the target logo image is adjusted according to the size of its corresponding placement unit, so that the target logo image is adapted to the size of the placement unit. In this way, the original logo image is replaced based on the size-adjusted target logo image to obtain the target document. Thus, automated logo image replacement can be achieved, which helps to reduce labor costs and improve replacement efficiency.
[0051] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this specification. Attached Figure Description
[0052] Figure 1 This is a flowchart illustrating an exemplary embodiment of the present application of a method for replacing a logo image within a document;
[0053] Figure 2 This is a comparison image of logo image replacement in a Word document, as illustrated in an exemplary embodiment of this application.
[0054] Figure 3 This is a comparison image illustrating logo image replacement within an Excel document, as shown in an exemplary embodiment of this application.
[0055] Figure 4 This is a schematic diagram illustrating the structure of a logo image replacement device within a document, as shown in an exemplary embodiment of this application.
[0056] Figure 5 This is a schematic diagram illustrating the structure of another logo image replacement device within a document, as shown in an exemplary embodiment of this application;
[0057] Figure 6 This is a hardware structure diagram of a computer device illustrated in an exemplary embodiment of this application. Detailed Implementation
[0058] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0059] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0060] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0061] In the process of modern enterprise digital operations, daily business operations generate a massive amount of electronic documents in heterogeneous formats, such as Word and Excel. These business documents not only carry the company's core business information but also serve as important windows for showcasing the company's brand image. With strategic adjustments and brand upgrades, the company logo, as the core visual identifier of the brand image, frequently needs to be changed and iterated. In practical applications, differences in logo versions within business documents can lead to inconsistencies in brand image expression, affecting the professionalism and standardization of the company's external presentation.
[0062] Currently, updating logos in business documents of different formats generally involves manual editing and replacement of each document. This method has significant technical bottlenecks: on the one hand, manual operation consumes a large amount of time and manpower when dealing with tens of thousands of documents; on the other hand, due to the diverse document formats and complex content, manual operation is prone to omissions and errors, and it is difficult to guarantee the consistency of the replacement effect. Therefore, improving the accuracy and efficiency of logo updates is an urgent problem to be solved.
[0063] Based on the above research, this disclosure provides a method for replacing logo images within a document. The method acquires an original document and a target logo image, and detects the document format type of the original document. Next, based on the document format type, a parsing algorithm corresponding to the document format type is used to parse the original document, obtaining attribute information for the placement unit corresponding to each original logo image. The placement unit is used to hold the logo image, and the attribute information includes size information. Then, for any original logo image, the size of the target logo image is adjusted according to the size information of the placement unit corresponding to the original logo image, so that the target logo image matches the size of the placement unit corresponding to the original logo image. Finally, the original logo image is replaced based on the size-adjusted target logo image to obtain the target document.
[0064] In this embodiment, since the placement unit is used to carry the logo image, for any original logo image, the size of the target logo image is adjusted according to the size of its corresponding placement unit, so that the target logo image is adapted to the size of the placement unit. In this way, the original logo image is replaced based on the size-adjusted target logo image to obtain the target document. Thus, automated logo image replacement can be achieved, which helps to reduce labor costs and improve replacement efficiency.
[0065] To facilitate understanding of this embodiment, a detailed description of the method for replacing logo images within a document disclosed in this disclosure embodiment will be provided first. The executing entity of the document logo image replacement method provided in this disclosure embodiment is generally an electronic device. The electronic device can be a server, which can be an independent physical server, a server cluster composed of multiple physical servers, or a distributed system. It can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data, and artificial intelligence platforms. In other embodiments, the electronic device can also be a terminal device, wherein the terminal device can be a mobile device, terminal, handheld device, computing device, vehicle-mounted device, etc.
[0066] In other embodiments, the method can also be applied to an implementation environment consisting of electronic devices and servers. Furthermore, the logo image replacement method within the document can also be implemented by a processor calling computer-readable instructions stored in memory.
[0067] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0068] Please participate in the attached... Figure 1 The above is a flowchart illustrating a method for replacing a logo image within a document, as shown in an exemplary embodiment of this application. Figure 1 As shown, the method for replacing the logo image within a document in this embodiment may include the following steps S101~S104:
[0069] S101: Obtain the original document and the target logo image, and detect the document format type of the original document.
[0070] The number of original documents can be one or more, and is not limited here. The original documents can be Word documents or Excel documents, and include the original logo image. Typically, each page of the original document includes the original logo image. Of course, in other embodiments, only some pages of the original document may include the original logo image.
[0071] In some implementations, the target logo image may be an updated version of the original logo image; in other implementations, the target logo image may be an image unrelated to the content of the original logo image, and this is not limited thereto.
[0072] It is understandable that after obtaining the original document, the document format type can be identified through the document format parsing algorithm, that is, the document format type (Word document or Excel document) of the original document can be detected.
[0073] S102: Based on the document format type of the original document, the original document is parsed using a parsing algorithm corresponding to the document format type to obtain the attribute information of the placement unit corresponding to each original logo image; the placement unit is used to carry the logo image, and the attribute information includes size information.
[0074] In this embodiment of the application, different document format types correspond to different parsing algorithms. Specifically, Word documents correspond to the Word document parsing algorithm, and Excel documents correspond to the Excel document parsing algorithm.
[0075] In this way, by parsing the original document using a parsing algorithm corresponding to the document format type, the attribute information of the placement unit corresponding to each original logo image can be obtained. The placement unit is used to carry the logo image, and the placement unit is different in the original document of different document format types.
[0076] The attribute information of the placement unit includes size information, specifically height and width information. In other embodiments, it may also include color information, position information, etc., which are not limited here.
[0077] It's important to note that containers don't exist explicitly in a document; rather, they are the underlying structure obtained from parsing the document. Each container can include one or more elements, such as image elements and text elements.
[0078] As mentioned above, the original document may include one or more original logo images. Therefore, after parsing, the attribute information of the placement unit corresponding to each original logo image can be obtained, that is, the size information of the placement unit corresponding to each original logo image can be obtained.
[0079] S103: For any original logo image, adjust the size of the target logo image according to the size information of the placement unit corresponding to the original logo image, so that the size of the target logo image is adapted to the size of the placement unit corresponding to the original logo image.
[0080] After obtaining the size information of the placement unit corresponding to each original logo image, the size of the target logo image can be adjusted according to the size information of the placement unit corresponding to the original logo image. Here, the size of the target logo image can be adjusted to the size of the placement unit corresponding to the original logo image, so that the size of the target logo image can be adapted to the size of the placement unit corresponding to the original logo image.
[0081] It should be noted that if the size information of the placement unit corresponding to different original logo images is different, then the target logo image needs to be resized multiple times.
[0082] S104: Replace the original logo image with the resized target logo image to obtain the target document.
[0083] Since the size of the target logo image after size adjustment is compatible with the size of the placement unit corresponding to the original logo image, the original logo image can be replaced based on the target logo image after size adjustment. In this way, each original logo image in the original document can be replaced with a target logo image of the same size, thus obtaining the target document.
[0084] The above method can automatically replace the original logo image. Compared with the "manual editing and replacement" method in related technical solutions, it can reduce labor costs, improve replacement efficiency and accuracy, and make the size of the target logo image match the size of the corresponding original logo image placement unit, thus improving the aesthetics of the logo in the document.
[0085] In some implementations, for step S102, if the document format type includes a Word document, the Word document parsing interface is called to parse the original document and obtain the size information of the placement unit corresponding to each original logo image.
[0086] In Word documents, the placement unit is an image container.
[0087] The following is a detailed explanation of the logo replacement process in Word documents.
[0088] When the Word document parsing interface is called to parse the original document and obtain the size information of the placement unit corresponding to each original logo image, the size information of at least one container corresponding to each header in the original document can be obtained by calling the Word document parsing interface to parse the original document, and the size information of the logo container corresponding to each original logo image can be determined from the size information corresponding to multiple containers respectively.
[0089] It is understandable that in a Word document, the logo image is usually located in the header. Therefore, by parsing the original document to obtain the XML document, we can further traverse the header of each page in the XML document to obtain the size information of at least one container corresponding to each header. Here, the header may contain multiple containers, and the multiple containers may be different from each other.
[0090] Thus, after obtaining the size information of at least one container corresponding to each header, the size information of the logo container corresponding to each original logo image can be determined from the size information of the multiple containers respectively.
[0091] This step can be understood as selecting a logo container from multiple containers. Since the logo container is used to hold the logo image, for each container, it can be determined whether the resource attribute information of the container includes an image element. If it includes an image element, the container is considered a logo container. After the determination, the size information of the container corresponding to the resource attribute information that includes the image element can be determined as the size information of the logo container corresponding to the original logo image.
[0092] For example, the xPath resource attribute information of each container in the XML document can be parsed. If the xPath resource attribute information contains the "drawing" element, it is determined that the container contains an image element.
[0093] Furthermore, after determining the size information of the logo container corresponding to the original logo image, for any original logo image, the size of the target logo image can be adjusted according to the size information of the logo container corresponding to the original logo image. In this way, when the original logo image is replaced based on the size-adjusted target logo image, the size of the target logo image can be adapted to the size of the logo container that carries it.
[0094] Optionally, to avoid the target logo image altering the header format, in this embodiment of the application, when replacing the original logo image based on the resized target logo image, a transparent canvas with the same size as the logo container is first created for each logo container. Then, the resized target logo image is pasted into the transparent canvas to generate a new logo image, and the original logo image is replaced based on the new logo image to obtain the target document.
[0095] It is understandable that the size information may differ for different logo containers. Therefore, a transparent canvas with the same size can be created for each logo container. Then, the target logo image with the adjusted size can be pasted into the transparent canvas to generate a new logo image that replaces the original logo image. This process ensures that after the new logo image is inserted into the image container, it does not change the aspect ratio of the logo itself, nor does it disrupt the original layout structure of the Word document header.
[0096] In some implementations, after replacing the original logo image with the resized target logo image to obtain the target document, the identification information of the resized target logo image in the target document and the identification information of the original logo image in the target document can be obtained. That is, the resized target logo image has a unique identifier in the target document, and the original logo image also has a unique identifier in the target document.
[0097] Furthermore, the identification information of the resized target logo image can be associated with the logo container, and the logo deletion interface can be called to delete the identification information of the original logo image associated with the logo container.
[0098] It is understandable that, since the logo container currently holds the target logo image, the target logo image can be associated with the logo container through the identification information. Since the original logo image has been replaced by the target logo image, the logo deletion interface can be called to delete the identification information of the original logo image associated with the logo container.
[0099] For example, please see Figure 2 This is a comparison image of a logo replacement provided as an exemplary embodiment of this application. Figure 2 As shown, the resized target logo image replaced the original logo image, and the format of the document header remained unchanged.
[0100] The following section provides a detailed explanation of the logo replacement process in Excel documents.
[0101] When the document format includes Excel documents, the Excel document parsing interface is called to parse the original document and obtain the size information of the placement unit corresponding to each original logo image.
[0102] In an Excel document, the unit is a cell (or a merged cell).
[0103] Typically, an Excel document can contain one or more worksheets. Therefore, an Excel document parsing interface can be called to parse the original document and obtain the image attribute information of each image contained in at least one worksheet of the original document.
[0104] The image attribute information may include image size, anchor point method, and anchor point position, etc., which are not limited here. The anchor point method includes fixed anchor point and non-fixed anchor point. Fixed anchor point means the image is located in a pre-defined cell in the worksheet. Typically, the logo's position in the worksheet is fixed; for example, an image located in the top-left cell is usually a logo image. If the image's anchor point method is non-fixed, then the image is considered not a logo image.
[0105] Then, for each image, the anchor point method of the image is determined from the image attribute information corresponding to the image, and the image with the fixed anchor point method is determined as the original logo image, and the size information of the cell corresponding to the original logo image in the original document is determined.
[0106] The cell corresponding to the original logo image in the original document can be either the smallest cell or a merged cell; there is no limitation on this.
[0107] Here, the row and column range of each cell in the original document can be obtained. Here, the cell can be a merged cell. For example, the row and column range of each cell in the original document can be [[min_col1,max_col1,min_row1,max_row1],[min_col2,max_col2,min_row2,max_row2],[min_col3,max_col3,min_row3,max_row3]…].
[0108] Optionally, when retrieving the row and column range of each cell in the original document, the Excel document properties interface can be used to obtain the cell's row height (Height_pt) and column width (Width_character), as well as the document's default row height and default column width parameters. If the cell's row height cannot be obtained, it is set to the default row height; if the cell's column width cannot be obtained, it is first set to the column width of the cell's previous column. If the column width of the previous column also cannot be obtained, it is set to the default column width. The default row height and default column width can be set according to actual needs.
[0109] Then, for each original logo image, determine whether the initial position of the cell containing the original logo image (e.g., [current_col, current_row]) is within the row and column range of any target cell. That is, determine whether the initial position of the cell containing the original logo icon is within the row and column range of each cell in the original document.
[0110] If the initial position of the cell containing the original logo image (e.g., [current_col, current_row]) is within the row and column range of any target cell (one of the cells in the original document), the range of the cell containing the original logo image is updated to the row and column range of the target cell. For example, the range of the cell containing the original logo image can be updated to [current_min_col, current_max_col, current_min_row, current_max_row]. Furthermore, the first unit conversion algorithm can be used to convert the range of the cell containing the original logo image into pixel units to obtain the physical size of the cell containing the original logo image.
[0111] It is understandable that the unit of the cell's row height (Height_pt) is points, and the unit of the column width (Width_character) is characters. Therefore, it may be necessary to convert them to pixels to obtain the physical size of the cell where the original logo image is located [Height_pixel, width_pixel].
[0112] As shown in formula (1), the expressions for converting the row height and column width of a cell into pixel units are as follows:
[0113] (1)
[0114] in, For column width, Column width in pixels. For high conduct, Row height in pixels.
[0115] After obtaining the physical dimensions of the cell containing the original logo image, the target logo image can be scaled according to its original aspect ratio, based on the physical dimensions of the cell containing the original logo image, to obtain a resized target logo image. The resized target logo image must meet the following conditions: the width of the resized target logo image is equal to the width of the cell, and the height of the resized target logo image is not greater than the height of the cell; or, the width of the resized target logo image is not greater than the width of the cell, and the height of the resized target logo image is equal to the height of the cell, for example, (Width2=width_pixel and Height2≤Height_pixel) or (Width2≤width_pixel and Height2=Height_pixel), where Width2 is the width of the resized target logo image and Height2 is the height of the resized target logo image.
[0116] In some implementations, when replacing the original logo image with a resized target logo image to obtain a target document, the center offset of the resized target logo image relative to the cell can be determined based on the physical size of the cell containing the original logo image and the size information of the resized target logo image. Then, based on the center offset and the row and column range of the cell, the anchor point position is determined. Finally, the resized target logo image is placed at the anchor point position, and the original logo image is deleted to obtain the target document.
[0117] It is understandable that the offset of the resized target logo image relative to the center of the cell can indicate whether the resized target logo image is located in the center of the cell. Therefore, based on the center offset and the row and column range of the cell, the anchor point position is determined, and the resized target logo image is placed at the anchor point position. This can make the resized target logo image centered in the horizontal and vertical directions within the cell, thereby improving the neatness and aesthetics of the resized target logo image in the target document.
[0118] Here, the center offset is in pixels. Therefore, the pixel-unit center offset [offset_x, offset_y] can be converted to the EMU-unit center offset [offset_x_emu, offset_y_emu] supported by Excel documents using a unit conversion formula. Then, based on the starting row and column number of the cell containing the resized target logo image, combined with the center offset [offset_x_emu, offset_y_emu], the anchor point position of the resized target logo image is determined. The Excel image insertion interface is then called to insert the resized target logo image into the anchor point position of the cell, thus completing the logo image replacement. At the same time, the original logo image can be deleted to obtain the target document.
[0119] Furthermore, after obtaining the target document, it can be saved and stored.
[0120] For example, please see Figure 3 The image shows a comparison of logo replacement in an Excel document, provided as an exemplary embodiment of this application. Figure 3 As shown, after replacing the original logo image with the resized target logo image, the document format remains unchanged, and the resized target logo image is centered in the corresponding cell.
[0121] Corresponding to the embodiments of the logo image replacement method in the aforementioned document, this application also provides embodiments of the logo image replacement device in the document.
[0122] Please refer to Figure 4 This is a schematic diagram illustrating the structure of a logo image replacement device within a document, as shown in an exemplary embodiment of this application. Figure 4 As shown, the logo image replacement device 400 within this document includes:
[0123] The detection module 410 is used to acquire the original document and the target logo image, and to detect the document format type of the original document;
[0124] The parsing module 420 is used to parse the original document according to the document format type and using a parsing algorithm corresponding to the document format type to obtain the attribute information of the placement unit corresponding to each original logo image; the placement unit is used to carry the logo image, and the attribute information includes size information;
[0125] The adjustment module 430 is used to adjust the size of the target logo image according to the size information of the placement unit corresponding to the original logo image for any original logo image, so that the size of the target logo image is adapted to the size of the placement unit corresponding to the original logo image;
[0126] Replacement module 440 is used to replace the original logo image based on the resized target logo image to obtain the target document.
[0127] In some implementations, the document format type includes a Word document or an Excel document; the parsing module 420 is specifically used for:
[0128] If the document format type includes a Word document, the Word document parsing interface is called to parse the original document to obtain the size information of the placement unit corresponding to each original logo image; or...
[0129] If the document format type includes an Excel document, the Excel document parsing interface is called to parse the original document and obtain the size information of the placement unit corresponding to each original logo image.
[0130] In some embodiments, when the document format type includes a Word document, the placement unit includes a logo container; the parsing module 420 is specifically used for:
[0131] The original document is parsed by calling the Word document parsing interface to obtain the size information of at least one container corresponding to each header in the original document, and the size information of the logo container corresponding to each original logo image is determined from the size information corresponding to multiple containers respectively.
[0132] In some implementations, each container has resource attribute information; the parsing module 420 is specifically used for:
[0133] For each container, determine whether the resource attribute information of the container includes image elements;
[0134] The size information of the container corresponding to the resource attribute information of the image element is determined as the size information of the logo container corresponding to the original logo image.
[0135] In some embodiments, the adjustment module 430 is specifically used for:
[0136] For any given original logo image, the size of the target logo image is adjusted based on the size information of the logo container corresponding to the original logo image.
[0137] Please refer to Figure 5 This is a schematic diagram illustrating the structure of a logo image replacement device within a document, as shown in an exemplary embodiment of this application. Figure 5 As shown, the logo image replacement device 400 within the document also includes an association module 450, which is used for:
[0138] Obtain the identification information of the resized target logo image in the target document and the identification information of the original logo image in the target document;
[0139] The identifier information of the resized target logo image is associated with the logo container, and the logo deletion interface is called to delete the identifier information of the original logo image associated with the logo container.
[0140] In some embodiments, the replacement module 440 is specifically used for:
[0141] For each logo container, create a transparent canvas of the same size as the logo container;
[0142] Paste the resized target logo image into the transparent canvas to generate a new logo image, and replace the original logo image with the new logo image to obtain the target document.
[0143] In some embodiments, when the document format type includes an Excel document, the placement unit includes a cell; the parsing module 420 is specifically used for:
[0144] Call the Excel document parsing interface to parse the original document and obtain the image attribute information of each image contained in at least one worksheet of the original document;
[0145] For each image, the anchor point method of the image is determined from the image attribute information corresponding to the image;
[0146] The image with a fixed anchor point is identified as the original logo image, and the size information of the cell corresponding to the original logo image in the original document is determined; wherein, a fixed anchor point means that the image is located in a cell at a preset position in the worksheet.
[0147] In some embodiments, the adjustment module 430 is specifically used for:
[0148] For any original logo image, calculate the physical size of the cell containing the original logo image, and adjust the size of the target logo image based on the physical size of the cell containing the original logo image.
[0149] In some embodiments, the adjustment module 430 is specifically used for:
[0150] Obtain the row and column range of each cell in the original document;
[0151] For each original logo image, determine whether the initial position of the cell containing the original logo image is within the row and column range of any target cell. If so, update the range of the cell containing the original logo image to the row and column range of the target cell.
[0152] Using a unit conversion algorithm, the range of the cell containing the original logo image is converted into pixel units to obtain the physical size of the cell containing the original logo image.
[0153] In some embodiments, the replacement module 440 is specifically used for:
[0154] Based on the physical size of the cell where the original logo image is located and the size information of the target logo image after size adjustment, determine the center offset of the target logo image relative to the cell;
[0155] The anchor point position is determined based on the center offset and the row and column range of the cell;
[0156] The resized target logo image is placed at the anchor point, and the original logo image is deleted to obtain the target document.
[0157] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0158] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0159] Corresponding to the above-described method for replacing logo images within documents, this disclosure also provides a computer device, such as... Figure 6 The diagram shown is a structural schematic of a computer device provided in an embodiment of this disclosure, including:
[0160] Computer device 600 includes a processor 610, an internal bus 620, memory 630, a network interface 640, and non-volatile memory 650, and may also include other hardware required for its functions. One or more embodiments of this specification can be implemented in software, for example, the processor 610 reads the corresponding computer program from the non-volatile memory 650 into the memory 630 and then runs it. Of course, besides software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution entity of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0161] The memory 630, also known as internal memory, is used to temporarily store the computational data in the processor 610, as well as the data exchanged with non-volatile memory 650 such as hard disk. The processor 610 exchanges data with non-volatile memory 650 through the memory 630.
[0162] In this embodiment, memory 630 is specifically used to store application code that executes the solution of this application, and its execution is controlled by processor 610. That is, when the computer device is running, processor 610 communicates with network interface 640, memory 630 and non-volatile memory 650 through internal bus 620, so that processor 610 executes the application code stored in memory 630 and non-volatile memory 650, thereby executing the logo image replacement method in the document described in the above method embodiment.
[0163] Processor 610 may be an integrated circuit chip with signal processing capabilities. The aforementioned processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor.
[0164] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the computer device 600. In other embodiments of this application, the computer device 600 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0165] This disclosure also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the logo image replacement method within a document as described in the above method embodiments. The storage medium can be either volatile or non-volatile computer-readable storage.
[0166] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the logo image replacement method in the document in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0167] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0168] The embodiments of the subject matter and functional operation described in this specification can be implemented in the following ways: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or combinations thereof. Embodiments of the subject matter described in this specification can be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible, non-transitory program carrier for execution by a data processing apparatus or for controlling the operation of a data processing apparatus. Alternatively or additionally, the program instructions may be encoded on artificially generated propagation signals, such as machine-generated electrical, optical, or electromagnetic signals, which are generated to encode information and transmit it to a suitable receiving device for execution by the data processing apparatus. The computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or combinations thereof.
[0169] The processing and logic flow described in this specification can be executed by one or more programmable computers that execute one or more computer programs to perform corresponding functions by operating on input data and generating output. The processing and logic flow can also be executed by dedicated logic circuitry—such as FPGAs (Field-Programmable Gate Arrays) or ASICs (Application-Specific Integrated Circuits), and the device can also be implemented as dedicated logic circuitry.
[0170] Suitable computers for executing computer programs include, for example, general-purpose and / or special-purpose microprocessors, or any other type of central processing unit. Typically, the central processing unit receives instructions and data from read-only memory and / or random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, a computer will also include one or more mass storage devices for storing data, such as disks, magneto-optical disks, or optical disks, or the computer will be operatively coupled to such mass storage devices to receive data from or transfer data to them, or both. However, a computer is not required to have such devices. Furthermore, a computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0171] Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices, such as semiconductor memory devices (e.g., EPROM, EEPROM, and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD-ROM and DVD-ROM disks. Processors and memory may be supplemented by or incorporated into dedicated logic circuitry.
[0172] While this specification contains numerous specific implementation details, these should not be construed as limiting the scope of any invention or the scope of the claims, but rather are primarily intended to describe features of specific embodiments of a particular invention. Certain features described in the various embodiments herein may also be implemented in combination in a single embodiment. Conversely, various features described in a single embodiment may also be implemented separately in various embodiments or in any suitable sub-combination. Furthermore, while features may function in certain combinations as described above and even initially claimed in this way, one or more features from a claimed combination may be removed from that combination in some cases, and a claimed combination may refer to a sub-combination or a variation thereof.
[0173] Similarly, although the operations are depicted in a specific order in the accompanying drawings, this should not be construed as requiring these operations to be performed in the specific order shown or sequentially, or requiring all illustrated operations to be performed to achieve the desired result. In some cases, multitasking and parallel processing may be advantageous. Furthermore, the separation of various system modules and components in the above embodiments should not be construed as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product or packaged into multiple software products.
[0174] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims may be performed in a different order and still achieve the desired result. Furthermore, the processes depicted in the drawings are not necessarily shown in a specific order or sequence to achieve the desired result. In some implementations, multitasking and parallel processing may be advantageous.
[0175] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A logo picture replacement method in a document, characterized by, The method comprises the following steps: obtaining an original document and a target logo picture, and detecting a document format type of the original document; the document format type comprises a Word document or an Excel document; according to the document format type of the original document, using a parsing algorithm corresponding to the document format type to parse the original document, to obtain attribute information of a placement unit corresponding to each original logo picture; the placement unit is used to carry a logo picture, and the attribute information comprises size information; for any original logo picture, according to the size information of the placement unit corresponding to the original logo picture, adjusting the size of the target logo picture, so that the target logo picture is adapted to the size of the placement unit corresponding to the original logo picture and the width-height ratio of the target logo picture itself is unchanged; based on the target logo picture after size adjustment, replacing the original logo picture to obtain a target document; the placement unit comprises a container in a Word document or a cell in an Excel document; according to the document format type of the original document, using a parsing algorithm corresponding to the document format type to parse the original document to obtain attribute information of a placement unit corresponding to each original logo picture, comprising: if the document format type is a Word document, calling a Word document parsing interface to parse the original document to obtain size information of at least one container corresponding to each header, and determining the size information of a logo container corresponding to the original logo picture from the size information corresponding to the plurality of containers respectively; the container is the underlying structure obtained by parsing the Word document; if the document format type is an Excel document, calling an Excel document parsing interface to parse the original document to obtain an anchor point mode of each picture, and determining the picture with a fixed anchor point mode as the original logo picture, and determining the size information of the cell corresponding to the original logo picture in the original document; wherein the fixed anchor point mode refers to that the picture is located in a cell at a preset position in a worksheet.
2. The method of claim 1, wherein, each container has resource attribute information; the size information of the logo container corresponding to the original logo picture is determined from the size information corresponding to the plurality of containers respectively, comprising: judging whether the resource attribute information of each container includes a picture element; determining the size information of the container corresponding to the resource attribute information including the picture element as the size information of the logo container corresponding to the original logo picture.
3. The method of claim 1, wherein, for any original logo picture, according to the size information of the logo container corresponding to the original logo picture, adjusting the size of the target logo picture, comprising: for any original logo picture, according to the size information of the logo container corresponding to the original logo picture, adjusting the size of the target logo picture.
4. The method according to any of claims 1 to 3, characterized in that, after the target document is obtained by replacing the original logo picture based on the target logo picture after size adjustment, the method further comprises: obtaining identification information of the size-adjusted target logo picture in the target document and identification information of the original logo picture in the target document; associating the identification information of the size-adjusted target logo picture with the logo container, and calling a logo deletion interface to delete the identification information of the original logo picture associated with the logo container.
5. The method according to any of claims 1 to 3, characterized in that the replacing of the original logo picture with the size-adjusted target logo picture to obtain a target document, comprising: for each logo container, creating a transparent canvas with the same size as the logo container; pasting the size-adjusted target logo picture into the transparent canvas to generate a new logo picture, and replacing the original logo picture with the new logo picture to obtain the target document.
6. The method of claim 1, wherein, the adjusting of the size of the target logo picture according to the size information of the placement unit corresponding to the original logo picture, comprising: for any original logo picture, calculating the physical size of the cell in which the original logo picture is located, and adjusting the size of the target logo picture according to the physical size of the cell in which the original logo picture is located.
7. The method of claim 6, wherein, the calculating of the physical size of the cell in which the original logo picture is located, comprising: obtaining the row and column range of each cell in the original document; for each original logo picture, judging whether the initial position of the cell in which the original logo picture is located is within the row and column range of any target cell, and if so, updating the range of the cell in which the original logo picture is located to the row and column range of the target cell; using a unit conversion algorithm to convert the range of the cell in which the original logo picture is located into a pixel unit to obtain the physical size of the cell in which the original logo picture is located.
8. The method of claim 7, wherein, the replacing of the original logo picture with the size-adjusted target logo picture to obtain a target document, comprising: determining the center offset of the size-adjusted target logo picture relative to the cell according to the physical size of the cell in which the original logo picture is located and the size information of the size-adjusted target logo picture; determining an anchor point position based on the center offset and the row and column range of the cell; placing the size-adjusted target logo picture at the anchor point position and deleting the original logo picture to obtain the target document.
9. A logo picture replacement apparatus in a document, characterized by, comprising: a detection module configured to obtain an original document and a target logo picture, and detect a document format type of the original document; the document format type comprises a Word document or an Excel document; a parsing module configured to parse the original document using a parsing algorithm corresponding to the document format type according to the document format type of the original document to obtain attribute information of a placement unit corresponding to each original logo picture; the placement unit is used to carry a logo picture, and the attribute information comprises size information; The adjusting module is configured to adjust the size of the target logo picture according to the size information of the placement unit corresponding to the original logo picture, so that the target logo picture is adapted to the size of the placement unit corresponding to the original logo picture and the width-to-height ratio of the target logo picture itself is unchanged. The replacing module is configured to replace the original logo picture with the target logo picture after the size adjustment, to obtain a target document. The placement unit includes a container in a Word document or a cell in an Excel document; and the analyzing module is specifically configured to: If the document format type is a Word document, a Word document analysis interface is called to analyze the original document, to obtain the size information of at least one container corresponding to each header, and to determine the size information of a logo container corresponding to the original logo picture from the size information of the containers respectively. If the document format type is an Excel document, an Excel document analysis interface is called to analyze the original document, to obtain the anchor point mode of each picture, to determine the original logo picture as a picture with a fixed anchor point mode, and to determine the size information of a cell corresponding to the original logo picture in the original document.
10. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the program to implement the steps of the logo picture replacement method in the document according to any one of claims 1-8.
11. A computer readable storage medium having stored thereon a computer program, characterized in that The program is executed by the processor to implement the steps of the logo picture replacement method in the document according to any one of claims 1-8.
Citation Information
Patent Citations
Method and device for replacing picture in document, electronic equipment and storage medium
CN112784541A
Multi-element document analysis method and system
CN120874816A
Systems and methods for performing bulk design edits
US20240303886A1