Picture directory batch updating method and device, storage medium and electronic equipment
By creating temporary directories, entering and compressing pictures in front-end development, and updating the picture directories on the server, the problem of cumbersome and error-prone image directories is solved, efficient batch updates are achieved, and project quality and progress are improved.
Patent Information
- Application Number
- CN202411688055.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-03-14
AI Technical Summary
During the front-end development process, the update task of image catalogs is cumbersome, time-consuming and error-prone, affecting the progress and quality of the project.
By obtaining the local image directory of the local project, creating a temporary directory that is consistent with it, entering the original image to be updated into the temporary directory, calling the API for compression, and storing the compressed image to the local image directory, and finally updating the remote image directory on the server.
It realizes batch compression and update of multiple pictures in the picture directory, improves the work efficiency of developers, reduces the error rate, and improves the development progress and quality of the project.
Smart Images

Figure CN119621679A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software development technology, and in particular to a method, device, storage medium and electronic device for batch updating of a picture directory. Background Art
[0002] During the front-end development process, developers need to frequently handle some repetitive tasks, such as compressing and packaging images and updating the image directory (which can be used in both test server updates and formal update scenarios). These tasks are very necessary. Currently, front-end designers usually package the designed original images and send them to relevant developers to update the image directory. Large-scale operations and updates are time-consuming and prone to errors. If these tedious tasks are handled manually (currently, most developers compress and download images on the website, then enter them into the project image directory, and then upload them to the server for update), it is not only inefficient, but also prone to errors, affecting the progress and quality of the project. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a method, device, storage medium and electronic device for batch updating of a picture directory, so as to implement batch updating of a picture directory in a simple and efficient manner.
[0004] In order to achieve the above purpose, the embodiments of the present application are implemented in the following manner:
[0005] In a first aspect, an embodiment of the present application provides a method for batch updating a picture directory, including: obtaining a local picture directory of a local project; locally creating a temporary directory that is consistent with the directory structure of the local picture directory, wherein the directory structure includes several levels and an indefinite number of folders; entering the original pictures to be updated into the temporary directory; compressing the original pictures in the temporary directory to obtain corresponding compressed pictures, and storing the compressed pictures in the local picture directory; updating the remote picture directory of the project to be updated on the server based on the local picture directory of the local project, wherein the local project and the project to be updated are the same project.
[0006] In combination with the first aspect, in a first possible implementation method of the first aspect, the original pictures to be updated are entered into a temporary directory, including: based on user operations, the original pictures to be updated are entered into corresponding positions in the temporary directory; or, tags are added to the original pictures to be updated in batches, and the original pictures to be updated are automatically entered into corresponding positions in the temporary directory based on the tags.
[0007] In combination with the first aspect, in a second possible implementation of the first aspect, the original images in the temporary directory are compressed, including: calling the tinify service through the API Key to compress the original images in the temporary directory.
[0008] In combination with the first aspect, in a third possible implementation of the first aspect, the compressed image is stored in a local image directory, including: obtaining the storage path specified by the original image in the temporary directory in the local image directory; and storing the compressed image in a corresponding position in the local image directory according to the specified storage path.
[0009] In combination with the first aspect, in a fourth possible implementation of the first aspect, there is a one-to-one mapping relationship between the temporary directory and the local picture directory, and the compressed pictures are stored in the local picture directory, including: based on the storage position of each original picture in the temporary directory and the mapping relationship between the temporary directory and the local picture directory, the compressed pictures are stored in the corresponding position in the local picture directory.
[0010] In combination with the first aspect, in a fifth possible implementation of the first aspect, a remote image directory of a project to be updated on a server is updated based on a local image directory of a local project, including: recursively detecting whether each compressed image in the local image directory has been stored in a corresponding position in the remote image directory; if there is no compressed image in the corresponding position in the remote image directory, uploading and storing the compressed image in the corresponding position in the remote image directory; if there is an image in the corresponding position in the remote image directory, but it is different from the compressed image in the local image directory, uploading and storing the compressed image in the corresponding position in the remote image directory.
[0011] In combination with the first aspect, in a sixth possible implementation of the first aspect, after the local image directory based on the local project updates the remote image directory of the project to be updated on the server, the temporary directory is recursively deleted, or before a temporary directory with a directory structure consistent with the local image directory is created locally, the last temporary directory is recursively deleted.
[0012] In the second aspect, an embodiment of the present application provides a batch update device for a picture directory, including: a picture directory acquisition unit, used to acquire a local picture directory of a local project; a temporary directory creation unit, used to locally create a temporary directory consistent with the directory structure of the local picture directory, wherein the directory structure includes several levels and an indefinite number of folders; an original picture entry unit, used to enter the original picture to be updated into the temporary directory; a picture compression storage unit, used to compress the original picture in the temporary directory, obtain the corresponding compressed picture, and store the compressed picture in the local picture directory; a picture directory update unit, used to update the remote picture directory of the project to be updated on the server based on the local picture directory of the local project, wherein the local project and the project to be updated are the same project.
[0013] In a third aspect, an embodiment of the present application provides a storage medium, which is arranged in an electronic device and includes a stored program, wherein when the program is running, the electronic device where the storage medium is located is controlled to execute the batch update method of the picture directory described in the first aspect or any one of the possible implementation methods of the first aspect.
[0014] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, and the program instructions, when loaded and executed by the processor, implement the steps of the batch update method of the picture directory described in the first aspect or any one of the possible implementation methods of the first aspect.
[0015] Beneficial effects:
[0016] 1. This solution obtains the local image directory of the local project, creates a temporary directory locally with the same directory structure as the local image directory; then enters the original image to be updated into the temporary directory, calls the API to compress the original image in the temporary directory, obtains the corresponding compressed image, and stores the compressed image in the local image directory, and then updates the remote image directory of the project to be updated on the server based on the local image directory of the local project. This method can realize batch compression and update of multiple images under the image directory, greatly improve the efficiency of developers in handling such tedious tasks with high repetition, effectively reduce the error rate, is developer-friendly, and is conducive to improving the progress and quality of project development.
[0017] 2. When the original images to be updated are entered into the temporary directory, the original images to be updated can be entered into the corresponding positions in the temporary directory based on user operations. For example, the user pulls the original images in batches into the corresponding positions in the temporary directory (understood as the subdirectories of the corresponding levels, i.e., the folders of the corresponding levels); or, tags are added in batches to the original images to be updated (this can be done by adding corresponding tags in batches to the original images, which may or may not be reflected in the file name. However, when it is reflected in the file name, it is necessary to name it accordingly when writing the code, and each tag corresponds to a position in the temporary directory. This has certain advantages and higher reliability when updating a large number of images), and the original images to be updated are automatically entered into the corresponding positions in the temporary directory based on the tags.
[0018] 3. Compressed images call the tinify service through the API Key to compress the original images in the temporary directory, so that batch compression processing of images can be realized efficiently and reliably. In order to simplify the process, by obtaining the storage path specified by the original image in the local image directory in the temporary directory, the compressed image is stored in the corresponding position in the local image directory according to the specified storage path, thereby eliminating the process of developers repeatedly uploading original images, compressing images, downloading compressed images, and manually entering compressed images in a single update (the traditional solution is to upload to the website-compress-download-store in the local image directory, which requires developers to manually operate more processes, and such tasks are highly repetitive and prone to errors. In addition, there is a limit on the number of compressed images on general websites, and developers have to repeat this process again and again). Alternatively, the compressed images can also be stored in the corresponding position in the local image directory based on the storage location of each original image in the temporary directory and the mapping relationship between the temporary directory and the local image directory. In this way, the automatic entry of compressed images can be accurately realized, eliminating the process of developers downloading and manually entering compressed images.
[0019] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 A flowchart of a method for batch updating a picture directory provided in an embodiment of the present application.
[0022] Figure 2 This is a diagram of the interface of the created temporary directory.
[0023] Figure 3 A schematic diagram of the interface for recording original images into a temporary directory.
[0024] Figure 4 A schematic diagram of a device for batch updating a picture directory provided in an embodiment of the present application.
[0025] Icons: 10- batch update device for picture directory; 11- picture directory acquisition unit; 12- temporary directory creation unit; 13- original picture entry unit; 14- picture compression storage unit; 15- picture directory update unit. DETAILED DESCRIPTION
[0026] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0027] See also Figure 1 , Figure 1 A flowchart of a method for batch updating a picture directory provided in an embodiment of the present application. In this embodiment, the method for batch updating a picture directory may include steps S10, S20, S30, S40, and S50.
[0028] When a developer needs to update a remote image directory of a project to be updated in a server (such as a test server or a formal server of a software project), step S10 can be executed through a local electronic device (such as a desktop computer or a laptop computer).
[0029] Step S10: Get the local image directory of the local project.
[0030] First, the electronic device can determine the local project that is consistent with the project to be updated in the server, and obtain the local image directory from the local project, where the directory structure of the local image directory contains several levels and an indefinite number of folders, and each folder can store several pictures that meet the project requirements (generally compressed to reduce the size of the pictures loaded in the application).
[0031] After obtaining the local image directory of the local project, the electronic device may execute step S20.
[0032] Step S20: creating a temporary directory locally that is consistent with the directory structure of the local picture directory, wherein the directory structure includes several levels and an indefinite number of folders.
[0033] In this embodiment, the electronic device can create a temporary directory with the same directory structure as the local picture directory, such as Figure 2 The operation steps here are regarded as initializing the picture directory. Specifically, a copy of the local picture directory of the local project is backed up to generate a temporary picture directory, and a corresponding folder (with several levels and quantities) is created as a temporary directory. In this embodiment, the picture directory, temporary directory, etc. mentioned all refer to the directory structure of the folder, covering the folder, and will not be separately mentioned later.
[0034] After the temporary directory is created, the electronic device may execute step S30.
[0035] Step S30: recording the original picture to be updated into a temporary directory.
[0036] In this embodiment, the electronic device can record the original image to be updated into the corresponding position in the temporary directory based on the user operation, such as Figure 3 For example, when the number of pictures is small (for example, no more than 100 pictures), the user (ie, the developer) can directly put the original pictures to be updated into the corresponding position in the temporary directory.
[0037] Alternatively, a more automated solution may be used to cope with a large number of pictures. For example, tags may be added to the original pictures to be updated in batches, and the original pictures to be updated may be automatically entered into corresponding positions in the temporary directory based on the tags.
[0038] For example, you can set the associated tag information according to the directory structure of the temporary directory (each folder at each level corresponds to a unique tag), and then add tag information to the original image (without reflecting it in the file name), for example, by adding in batches after selection, so as to add tags in batches to the original images to be updated. The advantage of this is that you don't need to select the pictures and drag them one by one into the corresponding folder (due to the operating logic of electronic devices, if you select the pictures in batches, copy them, and then select the corresponding folder, it may involve multiple clicks to jump to the corresponding subdirectory to paste), which is relatively more troublesome and prone to errors.
[0039] Of course, you can also use the file name to reflect the tag information, so that the image is assigned to the corresponding location in the temporary directory, but this method requires developers to maintain consistent naming when writing code. This is not so convenient when cross-personnel collaborative development is in progress because different developers have different habits.
[0040] Therefore, when the original pictures to be updated are entered into the temporary directory, the original pictures to be updated can be entered into the corresponding positions in the temporary directory based on user operations. For example, the user pulls the original pictures in batches into the corresponding positions in the temporary directory (understood as the subdirectories of the corresponding levels, i.e., the folders of the corresponding levels); or, tags are added in batches to the original pictures to be updated (this can be done by adding corresponding tags in batches to the original pictures, which may or may not be reflected in the file name. However, when it is reflected in the file name, it is necessary to name it accordingly when writing the code, and each tag corresponds to a position in the temporary directory. This has certain advantages and higher reliability when updating a large number of pictures), and the original pictures to be updated are automatically entered into the corresponding positions in the temporary directory based on the tags.
[0041] After recording the original picture to be updated into the temporary directory, the electronic device may execute step S40.
[0042] Step S40: compress the original image in the temporary directory to obtain a corresponding compressed image, and store the compressed image in the local image directory.
[0043] In this embodiment, the electronic device can call the tinify service through the API Key to compress the original image in the temporary directory.
[0044] After compressing the image, you can get the storage path specified by the original image in the local image directory in the temporary directory, and then store the compressed image to the corresponding location in the local image directory according to the specified storage path (this method is more direct).
[0045] Of course, it is also possible to establish a one-to-one mapping relationship between the temporary directory and the local image directory, so that based on the storage location of each original image in the temporary directory and the mapping relationship between the temporary directory and the local image directory, the compressed image is stored in the corresponding location in the local image directory (this solution is adapted to the solution of adding batch tags to the original images to be updated in the previous article).
[0046] Of course, this process will set up some judgment logic to ensure that every original image that needs to be compressed in the temporary directory can be compressed and stored in the corresponding position of the local image directory (it may also involve replacement, that is, a picture exists in the local image directory, but it needs to be updated and modified later. The two have the same name, but the size and data are generally different. After comparison, if they are inconsistent, they can be replaced. The comparison scheme can be to compare the MD5 values generated based on various information). In this way, batch compression of original images in the temporary directory can be achieved and automatic storage in the local image directory can be achieved, reducing the tedious operations of developers and effectively improving project progress and quality.
[0047] The compressed images call the tinify service through the API Key to compress the original images in the temporary directory, so that batch compression processing of images can be realized efficiently and reliably. In order to simplify the process, the storage path specified by the original images in the temporary directory in the local image directory is obtained, and the compressed images are stored in the corresponding position in the local image directory according to the specified storage path, thereby eliminating the process of developers repeatedly uploading original images, compressing images, downloading compressed images, and manually entering compressed images in a single update (the traditional solution is to upload to the website-compress-download-store in the local image directory, which requires developers to manually operate more processes, and such tasks are highly repetitive and prone to errors. In addition, there is a limit on the number of compressed images on general websites, and developers have to repeat this process again and again). Alternatively, the compressed images can also be stored in the corresponding position in the local image directory based on the storage location of each original image in the temporary directory and the mapping relationship between the temporary directory and the local image directory. In this way, the automatic entry of compressed images can be accurately realized, eliminating the process of developers downloading and manually entering compressed images.
[0048] After storing the compressed image in the local image directory, the electronic device may execute step S50.
[0049] Step S50: updating the remote image directory of the project to be updated on the server based on the local image directory of the local project, wherein the local project and the project to be updated are the same project.
[0050] In this embodiment, the electronic device may update the remote image directory of the to-be-updated project on the server based on the local image directory of the local project.
[0051] Exemplarily, the electronic device may recursively detect whether each compressed image in the local image directory has been stored in a corresponding location in the remote image directory.
[0052] If there is no compressed image in the corresponding position of the remote image directory, upload and store the compressed image to the corresponding position of the remote image directory. If there is an image in the corresponding position of the remote image directory, but it is different from the compressed image in the local image directory, upload and store the compressed image to the corresponding position of the remote image directory. That is, the local image directory of the local project is used to overwrite the remote image directory of the project to be updated on the server.
[0053] After the update is complete, the temporary directory can be recursively deleted. Of course, the temporary directory can also be deleted before the next use (specifically before creating a temporary directory with the same directory structure as the local image directory locally), which will not hinder subsequent use.
[0054] By obtaining the local image directory of the local project, a temporary directory with the same directory structure as the local image directory is created locally; then the original image to be updated is entered into the temporary directory, the API is called to compress the original image in the temporary directory, the corresponding compressed image is obtained, and the compressed image is stored in the local image directory, and then the remote image directory of the project to be updated on the server is updated based on the local image directory of the local project. This method can realize batch compression and update of multiple images under the image directory, greatly improving the efficiency of developers in handling such tedious tasks with high repetition, effectively reducing the error rate, being developer-friendly, and conducive to improving the progress and quality of project development.
[0055] See also Figure 4 Based on the same inventive concept, this embodiment provides a batch updating device 10 for a picture directory, comprising:
[0056] The picture directory obtaining unit 11 is used to obtain a local picture directory of a local project.
[0057] The temporary directory creation unit 12 is used to locally create a temporary directory that is consistent with the directory structure of the local picture directory, wherein the directory structure includes several levels and an indefinite number of folders.
[0058] The original picture recording unit 13 is used to record the original picture to be updated into the temporary directory.
[0059] The image compression storage unit 14 is used to compress the original image in the temporary directory to obtain a corresponding compressed image, and store the compressed image in the local image directory.
[0060] The picture directory updating unit 15 is used to update the remote picture directory of the project to be updated on the server based on the local picture directory of the local project, wherein the local project and the project to be updated are the same project.
[0061] In this embodiment, the original picture entry unit 13 is specifically used to: based on user operations, enter the original pictures to be updated into the corresponding positions in the temporary directory; or, batch add tags to the original pictures to be updated, and automatically enter the original pictures to be updated into the corresponding positions in the temporary directory based on the tags.
[0062] In this embodiment, the image compression storage unit 14 is specifically used to call the tinify service through the API Key to compress the original image in the temporary directory.
[0063] In this embodiment, the image compression storage unit 14 is specifically used to: obtain the storage path specified by the original image in the temporary directory in the local image directory; and store the compressed image to the corresponding position in the local image directory according to the specified storage path.
[0064] In this embodiment, the image compression storage unit 14 is specifically used to store the compressed image in a corresponding position in the local image directory based on the storage position of each original image in the temporary directory and the mapping relationship between the temporary directory and the local image directory.
[0065] In this embodiment, the picture directory updating unit 15 is specifically used to: recursively detect whether each compressed picture in the local picture directory has been stored in the corresponding position in the remote picture directory; if there is no compressed picture in the corresponding position in the remote picture directory, upload and store the compressed picture in the corresponding position in the remote picture directory; if there is a picture in the corresponding position in the remote picture directory, but it is different from the compressed picture in the local picture directory, upload and store the compressed picture in the corresponding position in the remote picture directory.
[0066] In this embodiment, the batch update device 10 for the picture directory also includes a temporary directory deletion unit, which is used to recursively delete the temporary directory after the picture directory update unit 15 updates the remote picture directory of the project to be updated on the server based on the local picture directory of the local project, or to recursively delete the last temporary directory before the temporary directory creation unit 12 creates a temporary directory locally with a directory structure consistent with the local picture directory.
[0067] This embodiment further provides a storage medium, which is disposed in an electronic device and includes a stored program. When the program is executed, the electronic device where the storage medium is located is controlled to execute the batch update method of the picture directory of this embodiment.
[0068] In addition, an embodiment of the present application further provides an electronic device, including a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, and when the program instructions are loaded and executed by the processor, the steps of the batch update method of the picture directory of this embodiment are implemented.
[0069] In summary, the embodiments of the present application provide a method, device, storage medium and electronic device for batch updating of a picture directory, which obtains the local picture directory of a local project, creates a temporary directory locally that is consistent with the directory structure of the local picture directory; then enters the original picture to be updated into the temporary directory, calls the API to compress the original picture in the temporary directory, obtains the corresponding compressed picture, and stores the compressed picture in the local picture directory, and then updates the remote picture directory of the project to be updated on the server based on the local picture directory of the local project. This method can realize batch compression and updating of multiple pictures under the picture directory, greatly improves the efficiency of developers in handling such tedious tasks with high repetition, effectively reduces the error rate, is developer-friendly, and is conducive to improving the progress and quality of project development.
[0070] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0071] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for batch updating of a picture directory, characterized in that: include: Get the local image directory of the local project; Create a temporary directory locally that is consistent with the directory structure of the local image directory, where the directory structure contains several levels and an indefinite number of folders; Enter the original pictures to be updated into the temporary directory; Compress the original image in the temporary directory to obtain the corresponding compressed image, and store the compressed image in the local image directory; The remote image directory of the project to be updated on the server is updated based on the local image directory of the local project, wherein the local project and the project to be updated are the same project.
2. The method for batch updating of a picture directory according to claim 1, characterized in that: Enter the original images to be updated into a temporary directory, including: Based on the user operation, the original image to be updated is recorded in the corresponding position in the temporary directory; Alternatively, tags are added in batches to the original images to be updated, and the original images to be updated are automatically entered into corresponding positions in the temporary directory based on the tags.
3. The method for batch updating of picture directories according to claim 1, characterized in that: Compress the original images in the temporary directory, including: Call the tinify service through the API Key to compress the original images in the temporary directory.
4. The method for batch updating of a picture directory according to claim 1, characterized in that: Store the compressed images in the local image directory, including: Get the storage path of the original image in the temporary directory in the local image directory; According to the specified storage path, the compressed image is stored in the corresponding location in the local image directory.
5. The method for batch updating of picture directories according to claim 1, characterized in that: There is a one-to-one mapping relationship between the temporary directory and the local image directory. The compressed images are stored in the local image directory, including: Based on the storage location of each original image in the temporary directory and the mapping relationship between the temporary directory and the local image directory, the compressed image is stored in the corresponding location in the local image directory.
6. The method for batch updating of a picture directory according to claim 1, characterized in that: Update the remote image directory of the project to be updated on the server based on the local image directory of the local project, including: Recursively check whether each compressed image in the local image directory has been stored in the corresponding location in the remote image directory; If there is no compressed image at the corresponding location in the remote image directory, upload the compressed image and store it at the corresponding location in the remote image directory; If there is an image at the corresponding location in the remote image directory, but it is different from the compressed image in the local image directory, upload the compressed image and store it at the corresponding location in the remote image directory.
7. The method for batch updating of picture directories according to claim 1, characterized in that: After the remote image directory of the project to be updated on the server is updated based on the local image directory of the local project, the temporary directory is recursively deleted, or before a temporary directory having a directory structure consistent with the local image directory is created locally, the last temporary directory is recursively deleted.
8. A batch update device for a picture directory, characterized in that: include: An image directory acquisition unit is used to acquire a local image directory of a local project; A temporary directory creation unit, used to locally create a temporary directory with a directory structure consistent with the directory of the local image directory, wherein the directory structure includes several levels and an indefinite number of folders; The original picture input unit is used to input the original picture to be updated into the temporary directory; The image compression storage unit is used to compress the original image in the temporary directory to obtain the corresponding compressed image, and store the compressed image in the local image directory; The image directory updating unit is used to update the remote image directory of the project to be updated on the server based on the local image directory of the local project, wherein the local project and the project to be updated are the same project.
9. A storage medium, characterized in that: The storage medium is set in the electronic device, and includes a stored program, wherein when the program is running, the electronic device where the storage medium is located is controlled to execute the batch update method of the picture directory according to any one of claims 1 to 7.
10. An electronic device comprising a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, characterized in that: When the program instructions are loaded and executed by the processor, the steps of the method for batch updating of the picture directory described in any one of claims 1 to 7 are implemented.