File editing method and device, electronic equipment and storage medium
By copying and batch replacing layers in PSD files, different versions of artboards are automatically generated, solving the problem of low efficiency for graphic designers when creating different versions of images, and achieving efficient image output and storage optimization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-03-13
AI Technical Summary
When graphic designers create different versions of the same product image, they need to manually create, edit, replace, and check each one, which is time-consuming, labor-intensive, and results in low output efficiency.
This program copies multiple artboards within the same PSD file and batch replaces the layers to be replaced in the copied artboards. It then uses layer replacement data to automatically generate different versions of the artboards, enabling automated operation within image editing software via a plugin.
It improves the efficiency of generating images of different versions, avoids the inconvenience of manual operation, realizes batch generation of images of different versions, and reduces manual operation steps and storage space.
Smart Images

Figure CN121661184A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of document editing, and in particular to a document editing method, apparatus, electronic device, and storage medium. Background Technology
[0002] In related technologies, graphic designers often need to create different versions of the same product image to meet the needs of major promotional events or other special scenarios. However, in the process of creating images, graphic designers need to manually create, edit, replace, and check each one, which is time-consuming and labor-intensive. Summary of the Invention
[0003] The purpose of this invention is to provide a file editing method, apparatus, electronic device, and storage medium that can copy multiple artboards in the same PSD file and batch replace the layers to be replaced in the copied artboards, thereby automatically generating different versions of artboards, improving the output efficiency of different versions of images, and avoiding the inconvenience caused by manual operation.
[0004] To solve the above-mentioned technical problems, the present invention provides a document editing method, comprising:
[0005] Obtain the PSD file to be edited, create artboards for all layers in the PSD file according to the canvas size of the PSD file, and set the artboards as the source artboards;
[0006] The system receives the input number of canvas splits, a marking instruction to set a layer in the source canvas as a marker layer, and layer replacement data corresponding to the marker layer.
[0007] Determine the relative distance between the first index of the marker layer and the second index of the source canvas; copy the source canvas according to the number of canvas splits to obtain a copied canvas; and determine the layer to be replaced corresponding to the marker layer in the copied canvas according to the relative distance.
[0008] The layer to be replaced in the copied canvas is replaced according to the layer replacement data of the marked layer to obtain multiple different versions of the canvas, so as to generate different versions of images using each version of the canvas.
[0009] Optionally, it also includes:
[0010] The layer identifiers of each layer are obtained from the metadata file of the PSD file, and the layer attributes of each layer are obtained through the API interface of the image editing software.
[0011] The layer type of each layer is determined based on the layer attributes, the layers are divided into corresponding sets according to the layer types, and the sets are output and displayed.
[0012] Determining the layer to be replaced corresponding to the marked layer in the copy canvas based on the relative distance includes:
[0013] Based on the relative distance, determine the layer to be replaced corresponding to the marked layer in the copy canvas, and determine the layer identifier of the layer to be replaced;
[0014] The layer to be replaced in the copied canvas is replaced according to the layer replacement data of the marked layer, including:
[0015] Obtain the replacement material from the layer replacement data, and replace the layer to be replaced using the replacement material according to the layer identifier of the layer to be replaced;
[0016] Alternatively, obtain the attribute adjustment parameters from the layer replacement data, obtain the layer attributes of the layer to be replaced according to the layer identifier of the layer to be replaced, and adjust the layer attributes according to the attribute adjustment parameters.
[0017] Optionally, replacing the layer to be replaced using the replacement material includes:
[0018] Obtain the target image size of the replacement material, the original image size of the layer to be replaced, and determine the preset size adjustment mode;
[0019] If the preset size adjustment mode is the width adaptation mode, then the scaling factor is determined using the width in the target image size and the width in the original image size;
[0020] If the preset size adjustment mode is height adaptation mode, then the scaling factor is determined using the height in the target image size and the height in the original image size;
[0021] The size of the original image is adjusted using the scaling factor to obtain the size of the replacement image. Based on the preset anchor point position in the PSD file and the size of the replacement image, the replacement placement position of the replacement material is determined. Based on the size of the replacement image and the replacement placement position, the layer to be replaced is replaced using the replacement material.
[0022] Optionally, adjusting the layer properties according to the property adjustment parameters includes:
[0023] Adjust the style parameters in the layer attributes according to the style parameters in the attribute adjustment parameters;
[0024] And / or, adjust the text content parameters in the layer attributes according to the text content parameters in the attribute adjustment parameters.
[0025] Optionally, it also includes:
[0026] The metadata information of each of the copied canvases is saved to the metadata file.
[0027] Optionally, before creating an artboard for all layers in the PSD file based on the canvas size of the PSD file, the method further includes:
[0028] Determine whether a canvas has been created in the PSD file;
[0029] If a canvas has already been created, the created canvas is used as the source canvas, and the process proceeds to the steps of receiving the input canvas fission quantity, setting the layer in the source canvas as the marker layer, and replacing the data of the layer corresponding to the marker layer.
[0030] If no artboard has been created, proceed to the step of creating an artboard for all layers in the PSD file based on the canvas size of the PSD file.
[0031] Optionally, it also includes:
[0032] Adjust the layout position of each of the copied artboards in the PSD file according to the third subscript of each of the copied artboards.
[0033] The present invention also provides a document editing device, comprising:
[0034] The canvas setting module is used to obtain the PSD file to be edited, create canvases for all layers in the PSD file according to the canvas size of the PSD file, and set the canvases as the source canvases;
[0035] The data receiving module is used to receive the input number of canvas splits, the marking instruction to set the layer in the source canvas as the marking layer, and the layer replacement data corresponding to the marking layer;
[0036] The canvas splitting module is used to determine the relative distance between the first index of the marker layer and the second index of the source canvas, to copy the source canvas according to the canvas splitting quantity to obtain a copied canvas, and to determine the layer to be replaced corresponding to the marker layer in the copied canvas according to the relative distance;
[0037] The canvas adjustment module is used to replace the layer to be replaced in the copied canvas according to the layer replacement data of the marked layer, so as to obtain multiple different versions of the canvas and generate different versions of images using each version of the canvas.
[0038] The present invention also provides an electronic device, comprising:
[0039] Memory, used to store computer programs;
[0040] A processor for implementing the file editing method described above when executing the computer program.
[0041] The present invention also provides a computer-readable storage medium storing computer-executable instructions, which, when loaded and executed by a processor, implement the file editing method described above.
[0042] This invention provides a file editing method, comprising: acquiring a PSD file to be edited; creating artboards for all layers in the PSD file according to the canvas size of the PSD file, and setting the artboards as source artboards; receiving input artboard splitting quantity, a marking instruction to set layers in the source artboard as marker layers, and layer replacement data corresponding to the marker layers; determining the relative distance between a first index of the marker layers and a second index of the source artboard; copying the source artboard according to the artboard splitting quantity to obtain a copied artboard; and determining the layer to be replaced corresponding to the marker layers in the copied artboard according to the relative distance; replacing the layer to be replaced in the copied artboard according to the layer replacement data of the marker layers to obtain multiple different versions of artboards, so as to generate different versions of images using each version of artboards.
[0043] The beneficial effects of this invention are as follows: This invention can acquire a PSD file to be edited, create artboards for all layers in the PSD file according to the canvas size of the PSD file, and set the artboards as the source artboards. Subsequently, it can receive the input artboard splitting quantity, a marking instruction to set the layers in the source artboard as marker layers, and layer replacement data corresponding to the marker layers. Then, it can determine the relative distance between the first index of the marker layer and the second index of the source artboard, copy the source artboard according to the artboard splitting quantity to obtain a copied artboard, and determine the layer to be replaced corresponding to the marker layer in the copied artboard based on the relative distance. Furthermore, it can replace the layer to be replaced in the copied artboard according to the layer replacement data of the marker layer, obtaining multiple different versions of artboards, so as to generate different versions of images using each version of artboard. In this way, this invention can copy multiple artboards in the same PSD file, and perform batch replacement of the corresponding layers to be replaced in the copied artboards according to the layer replacement data set by the user for the marker layers in the source artboard. This can automatically generate different versions of artboards, thereby automatically generating different versions of images, avoiding the inconvenience of manual operation, and improving the output efficiency of different versions of images.
[0044] The present invention also provides a document editing device, an electronic device, and a computer-readable storage medium, which have the above-mentioned beneficial effects. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0046] Figure 1 A flowchart of a document editing method provided in an embodiment of the present invention;
[0047] Figure 2 A flowchart illustrating another document editing method provided in an embodiment of the present invention;
[0048] Figure 3 This is a structural block diagram of a document editing device provided in an embodiment of the present invention;
[0049] Figure 4 This is a structural block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0051] In related technologies, graphic designers often need to create different versions of the same product image to meet the needs of major promotional events or other special scenarios. However, in the process of creating images, graphic designers need to manually create, edit, replace, and check each one, which is time-consuming and labor-intensive. For example, graphic designers need to keep the product image and core mechanism unchanged, only adjusting elements such as background, price, and copy; in addition, after generating multiple images, graphic designers need to check and manually fine-tune each one, which is inefficient.
[0052] In view of this, to address the technical problem of how to improve the output efficiency of multiple versions of images, the present invention provides a file editing method that can copy multiple artboards in the same PSD file and batch replace the layers to be replaced in the copied artboards, thereby automatically generating different versions of artboards, which can improve the output efficiency of different versions of images and avoid the inconvenience caused by manual operation.
[0053] It should be noted that this embodiment can set up a plugin for image editing software (such as Photoshop) to execute the method provided in this embodiment. This plugin can be divided into a front-end module and a back-end module. For the front-end module, this embodiment can embed a browser framework (such as the CEF framework, Chromium Embedded Framework, or Chromium browser embedding framework) into the image editing software, and execute the front-end script of the front-end module within the browser framework, thereby setting up a front-end interactive interface within the browser framework and receiving instructions and data input by the user through the front-end interactive interface. For the back-end module, its corresponding back-end script can be an extended script running in the image editing software environment (such as the Extendscript script supported by Photoshop). This embodiment can set automated operations (such as layer modification and artboard generation) in the back-end script. The front-end module and the back-end module can communicate bidirectionally through a bridging library. In this way, the front-end module can receive instructions or data input by the user and send these instructions or data to the back-end module through the bridging library; the back-end module can perform automated operations according to the input instructions or data and return the operation results to the front-end module.
[0054] For easier understanding, please refer to Figure 1 , Figure 1 A flowchart of a document editing method provided in an embodiment of the present invention, the method may include:
[0055] S101. Obtain the PSD file to be edited, create artboards for all layers in the PSD file according to the canvas size of the PSD file, and set the artboards as the source artboards.
[0056] First, let's briefly introduce PSD files, canvas, layers, and artboards. PSD files are a proprietary format used by image editing software, allowing graphic designers to edit images. The canvas is the basic working platform in image editing software, used to determine the size and visible area of the image design. Layers are hierarchical elements in image editing software, supporting independent editing, blending modes, and opacity adjustments; they are the basic units that make up a PSD file. Artboards are independent design areas in image editing software. Each artboard can independently manage multiple layers, allowing multiple versions or sizes of image designs to be managed within the same PSD file based on multiple artboards.
[0057] To reduce the storage size required for saving multiple versions of image design drafts and avoid creating separate PSD files for each version, while also facilitating simultaneous viewing of different versions, this embodiment can generate multiple artboards from a single PSD file and use each artboard to save different versions of the image design drafts. This allows for saving multiple versions of the image design drafts using the same PSD file, reducing the number of files and storage size, while also enabling the display of different versions of the image design drafts within the same PSD file for convenient editing and review.
[0058] Understandably, since different versions of the graphic design drafts remain unchanged in terms of product images and core content, with only minor differences in background, price, and text, it's advisable to first set a source artboard in the PSD file, and then generate other artboards based on this source artboard. Specifically, this step creates artboards for all layers in the PSD file according to the canvas size of the PSD file, and sets these artboards as the source artboard. At this point, all layers in the PSD file belong to the source artboard.
[0059] Of course, if a canvas has already been created in the PSD file, step S102 can be executed directly. Therefore, before executing this step, it can be determined whether a canvas has already been created in the PSD file. If it has been created, the created canvas can be used as the source canvas, and step S102 can be executed. If it has not been created, this step can be executed.
[0060] Therefore, before creating artboards for all layers in the PSD file based on the canvas size of the PSD file, the following can also be included:
[0061] Step 11: Determine if a canvas has been created in the PSD file; if a canvas has been created, proceed to Step 12; if no canvas has been created, proceed to Step 13.
[0062] Step 12: Use the created canvas as the source canvas, and proceed to the steps of receiving the input canvas fission quantity, setting the layer in the source canvas as the marker layer, and replacing the data of the corresponding layer of the marker layer.
[0063] Step 13: If no artboard has been created, proceed to the step of creating artboards for all layers in the PSD file based on the canvas size of the PSD file.
[0064] Furthermore, to facilitate users in selecting which layers in the source artboard to replace or modify, this step can also obtain the layer identifiers and layer attributes. The layer identifier is a unique identifier for the layer within the PSD file and can be obtained from the PSD file's metadata file (XML file). Layer attributes can include layer type (Type), layer name (Name), layer box size (Bbox), layer style (Style), and layer text content (Content), which can be obtained through the API interface of image editing software. After obtaining the layer identifiers and layer attributes, this embodiment can locate layers using the layer identifiers and determine the layer type of each layer based on the layer attributes. Layers are then grouped into corresponding sets based on their layer types, and the layer type and other layer attributes of each layer are displayed based on the sets, making it convenient for users to identify the layers that need to be replaced or adjusted.
[0065] Based on this, the method may also include:
[0066] Step 21: Obtain the layer identifier of each layer from the metadata file of the PSD file, and obtain the layer attributes of each layer through the API interface of the image editing software.
[0067] Step 22: Determine the layer type of each layer based on the layer attributes, divide the layers into corresponding sets according to the layer type, and output and display the sets.
[0068] S102, Receive the input number of canvas splits, the marking instruction to set the layer in the source canvas as the marking layer, and the layer replacement data corresponding to the marking layer.
[0069] In this step, users can input the number of canvases to be split through the front-end interface. This number represents the number of canvases that need to be split. Additionally, users can use the front-end interface to set the layers that need to be replaced or adjusted as marker layers, and set corresponding layer replacement data for the marker layers. This layer replacement data can include replacement materials for the marker layers, used to replace materials on the marker layers, such as replacing the background; it can also include attribute adjustment parameters for the marker layers, such as style parameters and text content parameters that need to be adjusted.
[0070] It is worth noting that users can choose to set different layer replacement data for different artboards, such as using background for artboard 1. Figure 1 Canvas 2 uses background Figure 2 This allows for different layer replacement operations to be performed on each canvas during canvas splitting, thus enabling the generation of different versions of canvases at once.
[0071] S103. Determine the relative distance between the first subscript of the marker layer and the second subscript of the source canvas. Copy the source canvas to obtain a copied canvas based on the number of canvas splits. Determine the layer to be replaced in the copied canvas based on the relative distance.
[0072] In this step, a duplicate canvas is created by copying the source canvas based on the number of canvas splits. This duplicate canvas is identical to the source canvas. Subsequently, this embodiment requires automatic replacement of the layers to be replaced in the duplicate canvas corresponding to the marked layers, based on the aforementioned layer replacement data, to complete the batch modification.
[0073] It is important to note that although the initial copied artboard contains the same layers as the source artboard, the layer labels of each layer have changed. Therefore, it is not possible to directly locate the layer to be replaced in the copied artboard based on the layer label of the marked layer. A separate positioning operation is required to determine the corresponding layer to be replaced within the copied artboard. To address this, this embodiment notes that layer indices within the artboard generally remain relatively fixed. That is, the relative distance between the layer indices of the marked layer (i.e., the first indices) and the artboard indices of the source artboard (i.e., the second indices) is consistent with the relative distance between the layer indices of the layer to be replaced and the artboard indices of the copied artboard. Therefore, this embodiment can determine the relative distance between the first indices of the marked layer and the second indices of the source artboard before copying the artboard, and then determine the corresponding layer to be replaced within the copied artboard based on this relative distance after copying, thereby obtaining the layer label of the layer to be replaced.
[0074] Based on this, determining the layer to be replaced in the copied artboard according to the relative distance of the marker layer can include:
[0075] Step 31: Determine the layer to be replaced in the copy artboard corresponding to the marked layer based on the relative distance, and determine the layer identifier of the layer to be replaced.
[0076] S104. Replace the layer to be replaced in the copied canvas according to the layer replacement data of the marked layer to obtain multiple different versions of the canvas, so as to generate different versions of images using each version of the canvas.
[0077] In this step, the layer to be replaced in the copied canvas can be replaced according to the layer replacement data of the marked layer mentioned above, so as to obtain multiple different versions of the canvas.
[0078] In one implementation, replacing the layer to be replaced in the copied artboard according to the layer replacement data of the marked layer may include:
[0079] Step 41: Obtain the replacement material from the layer replacement data, and replace the layer to be replaced using the replacement material according to the layer identifier of the layer to be replaced.
[0080] In this embodiment, the layer to be replaced can be replaced with a different image. Since the size of the replacement image may differ from the size of the layer to be replaced, the size of the replacement image can be adaptively adjusted. Specifically, this embodiment can obtain the target image size of the replacement image, the original image size of the layer to be replaced, and determine a preset size adjustment mode. If the preset size adjustment mode is a width adaptation mode, the scaling factor can be determined using the width in the target image size. If the preset size adjustment mode is a height adaptation mode, the scaling factor can be determined using the height in the target image size. The scaling factor can be expressed as:
[0081] ;
[0082] Where s represents the scaling factor, W target W represents the width in the target image size. src H represents the width in the original image size. target H represents the height in the target image size. src This represents the height within the original image size. Subsequently, the original image size can be adjusted using a scaling factor to obtain the replacement image size. The replacement material needs to be resized according to the replacement image size. The adjusted size can be represented as:
[0083] ;
[0084] Where W' and H' represent the adjusted width and height.
[0085] In addition, to maintain visual alignment, this embodiment can keep the preset anchor point position in the PSD file unchanged, and determine the replacement placement position of the replacement material based on the preset anchor point position in the PSD file and the size of the replacement image. For the center anchor point mode, this embodiment can recalculate the position coordinates of the upper left corner of the replacement material, which can be expressed as:
[0086] ;
[0087] Where (x',y') represents the coordinates of the top left corner of the replacement material, and (x0,y0) represents the coordinates of the preset anchor point.
[0088] Based on this, replacing the layer to be replaced using replacement materials can include:
[0089] Step 51: Obtain the target image size of the replacement material, the original image size of the layer to be replaced, and determine the preset size adjustment mode;
[0090] Step 52: If the preset size adjustment mode is width adaptation mode, then the scaling factor is determined using the width in the target image size and the width in the original image size;
[0091] Step 53: If the preset size adjustment mode is height adaptation mode, then the scaling factor is determined using the height in the target image size and the height in the original image size;
[0092] Step 54: Adjust the size of the original image using the scaling factor to obtain the size of the replacement image. Based on the preset anchor point position and the size of the replacement image in the PSD file, determine the replacement placement position of the replacement material. Then, based on the replacement image size and the replacement placement position, use the replacement material to replace the layer to be replaced.
[0093] In another implementation, replacing the layer to be replaced in the copied artboard based on the layer replacement data of the marked layer may include:
[0094] Step 61: Obtain the attribute adjustment parameters from the layer replacement data, obtain the layer attributes of the layer to be replaced based on the layer identifier of the layer to be replaced, and adjust the layer attributes according to the attribute adjustment parameters.
[0095] In this embodiment, the layer properties of the layer to be replaced can also be adjusted. Specifically, the property adjustment parameters can include style parameters to be adjusted, such as font size and style. In addition, the property adjustment parameters can include content parameters to be adjusted, so as to adjust the text content in the layer to be replaced.
[0096] Based on this, adjusting layer properties according to attribute adjustment parameters can include:
[0097] Step 71: Adjust the style parameters in the layer properties according to the style parameters in the attribute adjustment parameters;
[0098] And / or, step 72: Adjust the text content parameters in the layer properties according to the text content parameters in the property adjustment parameters.
[0099] After completing the above adjustments, this embodiment can save the metadata of each copied canvas to a metadata file to obtain different versions of canvases. This allows for the generation of different versions of images using different versions of canvases, enabling the batch creation of multiple versions of images, improving output efficiency, and reducing manual operations.
[0100] Furthermore, to facilitate user review of image design drafts, this embodiment can also adjust the layout position of each copied artboard in the PSD file according to the artboard subscript (i.e., the third subscript) of each copied artboard, thereby displaying each artboard in a mesh layout in the PSD file.
[0101] Based on this, the method may also include:
[0102] Step 81: Adjust the layout position of each copied artboard in the PSD file according to the third subscript of each copied artboard.
[0103] Based on the above embodiments, this invention can acquire a PSD file to be edited, create artboards for all layers in the PSD file according to the canvas size of the PSD file, and set the artboards as the source artboards. Subsequently, it can receive the input artboard splitting quantity, a marking instruction to set layers in the source artboard as marker layers, and layer replacement data corresponding to the marker layers. Then, it can determine the relative distance between the first index of the marker layer and the second index of the source artboard, copy the source artboard according to the artboard splitting quantity to obtain a copied artboard, and determine the layer to be replaced corresponding to the marker layer in the copied artboard based on the relative distance. Furthermore, it can replace the layer to be replaced in the copied artboard according to the layer replacement data of the marker layer, obtaining multiple different versions of artboards, and using each version of the artboard to generate different versions of images. In this way, this invention can copy multiple artboards in the same PSD file and perform batch replacement of the corresponding layers to be replaced in the copied artboards according to the layer replacement data set by the user for the marker layers in the source artboard. This can automatically generate different versions of artboards, thereby automatically generating different versions of images, avoiding the inconvenience of manual operation, and improving the output efficiency of different versions of images.
[0104] The following flowchart provides a complete explanation of the document editing method described above. Please refer to it. Figure 2 , Figure 2 A flowchart of another file editing method provided in an embodiment of the present invention, the method may include:
[0105] 1. Activate the plugin:
[0106] Open Photoshop, open the first most recent document, and activate the plugin.
[0107] 2. Package all layers into one artboard:
[0108] Based on the visible layers, use the current document size as the artboard size and use the artboard as the source artboard.
[0109] 3. Add data rows:
[0110] Users can add a few data rows to the plugin, which determines how many canvases they want to create.
[0111] 4. Copy the source canvas:
[0112] The XML records the ID of the marker layer. The ID will change after copying the artboard. Before each split, it is necessary to calculate the index of the marker layer and the index of the artboard to which it belongs, so as to obtain the relative distance between the layer and the artboard. Then, the layer to copy the artboard is located based on the relative distance.
[0113] 5. Locate and modify the layer:
[0114] (1) Without altering the original PSD parsing process, this invention achieves intelligent classification, semantic tagging, and layout optimization of text and image layers (including smart objects) through secondary analysis and semantic recognition of existing layer information.
[0115] The system does not need to re-parse the PSD file structure; it only performs incremental recognition and optimization based on the obtained layer tree and attribute data, thereby significantly improving processing efficiency and scalability.
[0116] The system receives structured layer data output by an external PSD parsing tool:
[0117] L={l1, l2, ..., l n};
[0118] Among them, l i This represents the i-th layer, where i is between 1 and n. Each layer has the following attributes:
[0119] l i ={type i name i bbox i style i , content i};
[0120] Among them, type i Indicates the layer type of the i-th layer, name i The bbox represents the layer name of the i-th layer. i This represents the layer box size of the i-th layer, style i This represents the layer style of the i-th layer, content. i This represents the text content of the i-th layer. i ∈{a, b, c, d, x, y, z…}, where a~z represent different types.
[0121] The system first performs a filtering operation based on the type value in the layer properties, where text layers correspond to type value x, image layers correspond to type value y, and smart object layers correspond to type value z.
[0122] This type value filtering mechanism can effectively distinguish different categories of layers and extract the target set for subsequent marking, replacement and layout adjustment steps, thereby improving processing efficiency and ensuring the accuracy of filtering results.
[0123] (2) During the canvas fission process, the present invention uses an adaptive replacement and layout reconstruction algorithm to ensure the coordination between visual elements and the consistency of the overall design when generating multiple canvas versions in batches.
[0124] After the user marks a layer with a corresponding replacement material (image or text), the system calculates an adaptive scaling factor based on the original layer's aspect ratio and the original size of the new material:
[0125] ;
[0126] Where s represents the scaling factor, W target W represents the width in the target image size. src H represents the width in the original image size. target H represents the height in the target image size. src This represents the height within the original image dimensions. The adjusted dimensions can be represented as:
[0127] The new dimensions after replacement are:
[0128] ;
[0129] Where W' and H' represent the adjusted width and height.
[0130] The system simultaneously maintains the anchor position to preserve visual alignment. For example, in center anchor mode:
[0131] ;
[0132] Where (x',y') represents the coordinates of the top left corner of the replacement material, and (x0,y0) represents the coordinates of the preset anchor point.
[0133] (3) The data persistence format for fission is XML.
[0134] 6. Adjust the canvas layout:
[0135] The copied canvas moves a specified distance to the right and down according to the index of the cyclic fission, forming a grid layout.
[0136] The beneficial effects of this invention are as follows:
[0137] 1. Efficiency Improvement:
[0138] The canvas splitting method generates multiple PSDs, reducing a significant number of manual steps (no need to save / open).
[0139] Centralized preview saves inspection time.
[0140] 2. Storage optimization:
[0141] Multiple artboards can share template resources, significantly reducing file size compared to traditional solutions.
[0142] 3. Enhanced flexibility:
[0143] It supports secondary modification of variables, and the newly iterated canvas can be used as a subsequent template canvas for further fission.
[0144] 4. It has good security.
[0145] From a data security perspective, PSD files already contain complete layer information, allowing users to directly view the content and attributes of each layer after obtaining the file. The embedded metadata is only used to record and describe the structure, configuration, and processing status of the layers, and does not contain any additional user privacy or sensitive information. Therefore, theoretically, it will not pose a new risk of privacy leakage.
[0146] The following describes the document editing device, electronic device, computer program product, and computer-readable storage medium provided in the embodiments of the present invention. The document editing device, electronic device, computer program product, and computer-readable storage medium described below can be referred to in correspondence with the document editing method described above.
[0147] Please refer to Figure 3 , Figure 3 This is a structural block diagram of a document editing device provided in an embodiment of the present invention. The device may include:
[0148] The canvas setting module 301 is used to obtain the PSD file to be edited, create a canvas for all layers in the PSD file according to the canvas size of the PSD file, and set the canvas as the source canvas;
[0149] The data receiving module 302 is used to receive the input number of canvas splits, the marking instruction to set the layer in the source canvas as the marking layer, and the layer replacement data corresponding to the marking layer;
[0150] The canvas splitting module 303 is used to determine the relative distance between the first subscript of the marker layer and the second subscript of the source canvas, copy the source canvas according to the number of canvas splits to obtain a copied canvas, and determine the layer to be replaced corresponding to the marker layer in the copied canvas according to the relative distance.
[0151] The canvas adjustment module 304 is used to replace the layer to be replaced in the copied canvas according to the layer replacement data of the marked layer, so as to obtain multiple different versions of the canvas and generate different versions of the image using each version of the canvas.
[0152] Optionally, the device may further include:
[0153] The metadata reading module is used to obtain the layer identifiers of each layer from the metadata file of the PSD file, and to obtain the layer attributes of each layer through the API interface of the image editing software.
[0154] The category display module is used to determine the layer type of each layer based on its attributes, divide the layers into corresponding sets according to their types, and output and display the sets.
[0155] The drawing board fission module 303 may include:
[0156] The layer positioning submodule is used to determine the corresponding layer to be replaced in the copied artboard based on the relative distance of the marked layer, and to determine the layer identifier of the layer to be replaced;
[0157] The drawing board adjustment module 304 may include:
[0158] The first replacement submodule is used to obtain replacement materials from the layer replacement data, and replace the layer to be replaced using the replacement materials according to the layer identifier of the layer to be replaced;
[0159] The second replacement submodule is used to obtain the attribute adjustment parameters in the layer replacement data, obtain the layer attributes of the layer to be replaced according to the layer identifier of the layer to be replaced, and adjust the layer attributes according to the attribute adjustment parameters.
[0160] Optionally, the first replacement submodule may include:
[0161] The acquisition unit is used to acquire the target image size of the replacement material, the original image size of the layer to be replaced, and to determine the preset size adjustment mode;
[0162] The first calculation unit is used to determine the scaling factor by using the width in the target image size and the width in the original image size if the preset size adjustment mode is the width adaptation mode.
[0163] The second calculation unit is used to determine the scaling factor by using the height in the target image size and the height in the original image size if the preset size adjustment mode is height adaptation mode.
[0164] The size and position adjustment unit is used to adjust the size of the original image using a scaling factor to obtain the size of the replacement image. Based on the preset anchor point position and the size of the replacement image in the PSD file, it determines the replacement placement position of the replacement material and uses the replacement material to replace the layer to be replaced according to the replacement image size and replacement placement position.
[0165] Optionally, the second replacement submodule may include:
[0166] The first parameter adjustment unit is used to adjust the style parameters in the layer attributes according to the style parameters in the attribute adjustment parameters;
[0167] The second parameter adjustment unit is used to adjust the text content parameters in the layer properties based on the text content parameters in the attribute adjustment parameters.
[0168] Optionally, the device may further include:
[0169] The metadata storage module is used to save the metadata information of each copied canvas to a metadata file.
[0170] Optionally, the device may further include:
[0171] The canvas creation control module is used to determine whether a canvas has been created in the PSD file. If a canvas has been created, it is used as the source canvas and proceeds to the steps of receiving the input canvas fission quantity, setting the layers in the source canvas as marker layers, and replacing the data of the corresponding layers of the marker layers. If no canvas has been created, it proceeds to the step of creating canvases for all layers in the PSD file according to the canvas size of the PSD file.
[0172] Optionally, the device may further include:
[0173] The layout adjustment module is used to adjust the layout position of each copied artboard in the PSD file based on the third subscript of each copied artboard.
[0174] Please refer to Figure 4 , Figure 4 This is a structural block diagram of an electronic device provided in an embodiment of the present invention. The embodiment of the present invention provides an electronic device 40, including a processor 41 and a memory 42; wherein, the memory 42 is used to store a computer program; the processor 41 is used to execute the file editing method provided in the foregoing embodiment when executing the computer program.
[0175] For details regarding the specific process of the above document editing method, please refer to the corresponding content provided in the foregoing embodiments, which will not be repeated here.
[0176] Furthermore, the memory 42, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, and the storage method can be temporary storage or permanent storage.
[0177] In addition, the electronic device 40 also includes a power supply 43, a communication interface 44, an input / output interface 45, and a communication bus 46; wherein, the power supply 43 is used to provide operating voltage for the various hardware devices on the electronic device 40; the communication interface 44 can create a data transmission channel between the electronic device 40 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this invention, and is not specifically limited here; the input / output interface 45 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0178] This invention also provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the file editing method described in the above embodiments.
[0179] Since the embodiments of the computer program product section correspond to the embodiments of the document editing method section, please refer to the description of the embodiments of the document editing method section for the embodiments of the computer program product section, and they will not be repeated here.
[0180] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the file editing method described in the above embodiments.
[0181] Since the embodiments of the computer-readable storage medium portion correspond to the embodiments of the file editing method portion, the embodiments of the storage medium portion are described in the description of the embodiments of the file editing method portion, and will not be repeated here.
[0182] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0183] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0184] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0185] The foregoing has provided a detailed description of a document editing method, apparatus, electronic device, and storage medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and core ideas of the present invention. It should be noted that those skilled in the art can make various improvements and modifications to the present invention without departing from its principles, and these improvements and modifications also fall within the protection scope of the present invention.
Claims
1. A document editing method, characterized in that, include: Obtain the PSD file to be edited, create artboards for all layers in the PSD file according to the canvas size of the PSD file, and set the artboards as the source artboards; The system receives the input number of canvas splits, a marking instruction to set a layer in the source canvas as a marker layer, and layer replacement data corresponding to the marker layer. Determine the relative distance between the first index of the marker layer and the second index of the source canvas; copy the source canvas according to the number of canvas splits to obtain a copied canvas; and determine the layer to be replaced corresponding to the marker layer in the copied canvas according to the relative distance. The layer to be replaced in the copied canvas is replaced according to the layer replacement data of the marked layer to obtain multiple different versions of the canvas, so as to generate different versions of images using each version of the canvas.
2. The document editing method according to claim 1, characterized in that, Also includes: The layer identifiers of each layer are obtained from the metadata file of the PSD file, and the layer attributes of each layer are obtained through the API interface of the image editing software. The layer type of each layer is determined based on the layer attributes, the layers are divided into corresponding sets according to the layer types, and the sets are output and displayed. Determining the layer to be replaced corresponding to the marked layer in the copy canvas based on the relative distance includes: Based on the relative distance, determine the layer to be replaced corresponding to the marked layer in the copy canvas, and determine the layer identifier of the layer to be replaced; The step of replacing the layer to be replaced in the copied canvas according to the layer replacement data of the marked layer includes: Obtain the replacement material from the layer replacement data, and replace the layer to be replaced using the replacement material according to the layer identifier of the layer to be replaced; Alternatively, obtain the attribute adjustment parameters from the layer replacement data, obtain the layer attributes of the layer to be replaced according to the layer identifier of the layer to be replaced, and adjust the layer attributes according to the attribute adjustment parameters.
3. The document editing method according to claim 2, characterized in that, The process of replacing the layer to be replaced using the replacement material includes: Obtain the target image size of the replacement material, the original image size of the layer to be replaced, and determine the preset size adjustment mode; If the preset size adjustment mode is the width adaptation mode, then the scaling factor is determined using the width in the target image size and the width in the original image size; If the preset size adjustment mode is height adaptation mode, then the scaling factor is determined using the height in the target image size and the height in the original image size; The size of the original image is adjusted using the scaling factor to obtain the size of the replacement image. Based on the preset anchor point position in the PSD file and the size of the replacement image, the replacement placement position of the replacement material is determined. Based on the size of the replacement image and the replacement placement position, the layer to be replaced is replaced using the replacement material.
4. The document editing method according to claim 2, characterized in that, The step of adjusting the layer attributes according to the attribute adjustment parameters includes: Adjust the style parameters in the layer attributes according to the style parameters in the attribute adjustment parameters; And / or, adjust the text content parameters in the layer attributes according to the text content parameters in the attribute adjustment parameters.
5. The document editing method according to claim 2, characterized in that, Also includes: The metadata information of each of the copied canvases is saved to the metadata file.
6. The document editing method according to claim 1, characterized in that, Before creating an artboard for all layers in the PSD file based on the canvas size of the PSD file, the process also includes: Determine whether a canvas has been created in the PSD file; If a canvas has already been created, the created canvas is used as the source canvas, and the process proceeds to the steps of receiving the input canvas fission quantity, setting the layer in the source canvas as the marker layer, and replacing the data of the layer corresponding to the marker layer. If no artboard has been created, proceed to the step of creating an artboard for all layers in the PSD file based on the canvas size of the PSD file.
7. The document editing method according to claim 1, characterized in that, Also includes: Adjust the layout position of each of the copied artboards in the PSD file according to the third subscript of each of the copied artboards.
8. A document editing device, characterized in that, include: The canvas setting module is used to obtain the PSD file to be edited, create canvases for all layers in the PSD file according to the canvas size of the PSD file, and set the canvases as the source canvases; The data receiving module is used to receive the input number of canvas splits, the marking instruction to set the layer in the source canvas as the marking layer, and the layer replacement data corresponding to the marking layer; The canvas splitting module is used to determine the relative distance between the first index of the marker layer and the second index of the source canvas, to copy the source canvas according to the canvas splitting quantity to obtain a copied canvas, and to determine the layer to be replaced corresponding to the marker layer in the copied canvas according to the relative distance; The canvas adjustment module is used to replace the layer to be replaced in the copied canvas according to the layer replacement data of the marked layer, so as to obtain multiple different versions of the canvas and generate different versions of images using each version of the canvas.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the file editing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when loaded and executed by a processor, implement the file editing method as described in any one of claims 1 to 7.