Picture processing method and device, computer device and storage medium
By dynamically adjusting image sizes on the server side and compressing them according to memory usage, the system crash issue caused by abnormal image loading was resolved, achieving efficient resource utilization and improved user experience.
Patent Information
- Application Number
- CN202111559105.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2041-12-20
AI Technical Summary
In software systems, image loading errors frequently cause system crashes, impacting user experience. Existing methods that limit the number and size of images to circumvent this problem are inconvenient.
By responding to the terminal's request, the system obtains the initial size of the image to be exported and the server's current used memory, calculates the total usage ratio, and performs image compression when the ratio exceeds a threshold until the ratio is within a preset range, then sends the compressed image to the terminal.
It effectively avoids system memory overflow, optimizes server resource utilization, improves user experience, and avoids fixed restrictions on image file uploading and display.
Smart Images

Figure CN114254227B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of picture processing, and in particular to a picture processing method and device, computer equipment, a storage medium and a computer program product. BACKGROUND
[0002] In order to increase the ease of use of a software system and improve the user experience, providing a function of maintaining picture resources in the background of the software system has become an important function of the software system. With the increasing requirements of the software system on the diversity and richness of picture resources, the administrator maintains more and more uploaded picture resources and picture displayed on the user interface, and the consumption of system performance caused by querying pictures during system page loading is also increasing, which can easily cause picture loading abnormalities and system crashes, and ultimately result in poor user experience.
[0003] In order to avoid such picture loading abnormalities and system crashes, the traditional method is to constrain the number and size of pictures uploaded by maintenance personnel, constrain the size and number of pictures displayed on the query page, and the like. These measures have great inconvenience. SUMMARY
[0004] Therefore, it is necessary to provide a picture processing method, device, computer equipment, computer readable storage medium and computer program product which can adaptively and dynamically adjust the picture size, and effectively avoid the situation of system crashes caused by memory overflow during page loading.
[0005] In a first aspect, the present application provides a picture processing method. The method comprises:
[0006] In response to an acquisition request for a picture to be exported sent by a terminal, obtaining an initial picture size of the picture to be exported and a current used memory of a server;
[0007] Based on the initial picture size and the current used memory, determining a total occupancy ratio of the picture to be exported and the current used memory to a total memory of the server;
[0008] When the total occupancy ratio is greater than a preset critical ratio, performing picture compression processing on the picture to be exported to obtain a compressed picture of the picture to be exported;
[0009] Sending the compressed picture to the terminal.
[0010] In one embodiment, the step of determining the total occupancy ratio of the picture to be exported and the current used memory to the total memory of the server based on the initial picture size and the current used memory comprises:
[0011] determining the memory required by the to-be-derived picture based on an initial picture size of the to-be-derived picture;
[0012] summing the memory required by the to-be-derived picture and the current used memory to obtain an occupied memory sum;
[0013] obtaining a ratio between the occupied memory sum and the total memory of the server as a total occupied proportion of the to-be-derived picture and the current used memory to the total memory of the server.
[0014] In one embodiment, the determining the memory required by the to-be-derived picture based on the initial picture size of the to-be-derived picture comprises:
[0015] obtaining a preset memory adjustment ratio; the memory adjustment ratio represents a ratio between the memory required by the to-be-derived picture and the initial picture size of the to-be-derived picture;
[0016] obtaining a product between the initial picture size of the to-be-derived picture and the memory adjustment ratio as the memory required by the to-be-derived picture.
[0017] In one embodiment, the performing picture compression processing on the to-be-derived picture to obtain a compressed picture comprises:
[0018] determining a picture compression ratio value of the to-be-derived picture based on the current used memory of the server, the total memory of the server and the preset critical proportion;
[0019] performing picture compression processing on the to-be-derived picture according to the picture compression ratio value to obtain the compressed picture.
[0020] In one embodiment, the performing picture compression processing on the to-be-derived picture to obtain a compressed picture further comprises:
[0021] obtaining an initial picture compression ratio value;
[0022] performing picture compression processing on the to-be-derived picture according to the initial picture compression ratio value to obtain an initial compressed picture;
[0023] judging whether a total occupied proportion of the initial compressed picture and the current used memory to the total memory of the server is greater than the critical proportion;
[0024] if the total occupied proportion is greater than the critical proportion, decreasing the initial picture compression ratio value to obtain a new picture compression ratio value, returning to the step of performing picture compression processing on the to-be-derived picture until the total occupied proportion is not greater than the critical proportion, and obtaining the compressed picture.
[0025] In one of the embodiments, the method further comprises:
[0026] When the total occupancy ratio of the to-be-exported picture and the current used memory to the total memory of the server is not greater than the preset critical ratio, the to-be-exported picture is returned to the terminal.
[0027] In a second aspect, the present application further provides a picture processing device. The device comprises:
[0028] The obtaining module is configured to obtain an initial picture size of the to-be-exported picture and a current used memory of a server in response to an obtaining request for the to-be-exported picture sent by a terminal.
[0029] The determining module is configured to determine a total occupancy ratio of the to-be-exported picture and the current used memory to the total memory of the server based on the initial picture size and the current used memory.
[0030] The compressing module is configured to perform picture compression processing on the to-be-exported picture to obtain a compressed picture of the to-be-exported picture when the total occupancy ratio is greater than a preset critical ratio.
[0031] The sending module is configured to send the compressed picture to the terminal.
[0032] In a third aspect, the present application further provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0033] The processor is configured to obtain an initial picture size of the to-be-exported picture and a current used memory of a server in response to an obtaining request for the to-be-exported picture sent by a terminal.
[0034] The processor is configured to determine a total occupancy ratio of the to-be-exported picture and the current used memory to the total memory of the server based on the initial picture size and the current used memory.
[0035] The processor is configured to perform picture compression processing on the to-be-exported picture to obtain a compressed picture of the to-be-exported picture when the total occupancy ratio is greater than a preset critical ratio.
[0036] The processor is configured to send the compressed picture to the terminal.
[0037] In a fourth aspect, the present application further provides a computer readable storage medium. The computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the following steps:
[0038] In response to the terminal sending an acquisition request for a picture to be exported, an initial picture size of the picture to be exported and current used memory of a server are acquired;
[0039] Based on the initial picture size and the current used memory, a total occupancy ratio of the picture to be exported and the current used memory to total memory of the server is determined;
[0040] When the total occupancy ratio is greater than a preset critical ratio, picture compression processing is performed on the picture to be exported to obtain a compressed picture of the picture to be exported;
[0041] The compressed picture is sent to the terminal.
[0042] In a fifth aspect, the present application further provides a computer program product. The computer program product comprises a computer program, which, when executed by a processor, implements the following steps:
[0043] In response to the terminal sending an acquisition request for a picture to be exported, an initial picture size of the picture to be exported and current used memory of a server are acquired;
[0044] Based on the initial picture size and the current used memory, a total occupancy ratio of the picture to be exported and the current used memory to total memory of the server is determined;
[0045] When the total occupancy ratio is greater than a preset critical ratio, picture compression processing is performed on the picture to be exported to obtain a compressed picture of the picture to be exported;
[0046] The compressed picture is sent to the terminal.
[0047] The picture processing method, device, computer device, storage medium and computer program product described above, before exporting the picture to be exported, compress the picture to be exported according to the initial picture size of the picture to be exported and the memory occupancy of the server, adaptively and dynamically adjust the picture size, maximize the use of server resources, can effectively avoid the memory overflow that may be caused by the export of a large picture file, effectively avoid the inconvenience caused by the evasive measures taken by the conventional picture export, and do not need to set the picture file upload size limit or the fixed compression ratio of picture display. BRIEF DESCRIPTION OF DRAWINGS
[0048] Figure 1 It is an application environment diagram of the picture processing method in one embodiment;
[0049] Figure 2 It is a flowchart of the picture processing method in one embodiment;
[0050] Figure 3Flowchart of picture processing method in another embodiment;
[0051] Figure 4 Block diagram of system for implementing picture processing method in an embodiment;
[0052] Figure 4.1 For Figure 4 Block diagram of picture export initialization device 410 in an embodiment;
[0053] Figure 4.2 For Figure 4 Block diagram of picture export dynamic adjustment device 420 in an embodiment;
[0054] Figure 4.3 For Figure 4 Block diagram of picture export device 430 in an embodiment;
[0055] Figure 5 Flowchart of picture export processing based on available memory to dynamically adjust picture compression ratio in an embodiment;
[0056] Figure 6 For Figure 4 Flowchart of picture export dynamic adjustment device 420 in an embodiment;
[0057] Figure 7 Block diagram of picture processing device in an embodiment;
[0058] Figure 8 Internal block diagram of computer device in an embodiment. DETAILED DESCRIPTION
[0059] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not intended to limit the present application.
[0060] The picture processing method provided by the embodiments of the present application can be applied to, for example, Figure 1The application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data required by the server 104 to process. The data storage system can be integrated on the server 104, or placed on the cloud or other network servers. In the application scenario of the present application, the terminal 102 sends an acquisition request for the picture to be exported to the server 104, and the server 104 responds to the acquisition request to obtain the initial picture size of the picture to be exported and the current used memory of the server, and based on the initial picture size and the current used memory, determine the total occupancy ratio of the picture to be exported and the current used memory to the total memory of the server, when the total occupancy ratio is greater than the preset critical ratio, the picture compression processing is carried out on the picture to be exported, and the compressed picture of the picture to be exported is obtained, and the compressed picture is sent to the server 104. Among them, the terminal 102 can be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices and portable wearable devices, Internet of Things devices can be smart speakers, smart televisions, smart air conditioners, smart car devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented by an independent server or a server cluster composed of multiple servers.
[0061] In one embodiment, as shown in Figure 2 , a picture processing method is provided, and the method is applied to Figure 1 the server 104 in the above application environment for example, including the following steps:
[0062] Step 210, in response to the acquisition request for the picture to be exported sent by the terminal, the initial picture size of the picture to be exported and the current used memory of the server are obtained.
[0063] Among them, the picture to be exported represents the picture that needs to be exported to the terminal for display through the server.
[0064] Among them, the initial picture size represents the size of the picture to be exported itself.
[0065] In a specific implementation, the terminal cannot directly access the picture stored in the external storage module such as a database, and needs to obtain the picture from the database through the server and return the picture to the terminal page through an interface for display, so as to realize the export and display of the picture in the database to the terminal. Therefore, when the terminal 102 needs to view the picture stored in the database, the terminal 102 can send an acquisition request for the to-be-exported picture to the server 104, and the server 104 obtains the to-be-exported picture from the database and obtains the initial picture size of the to-be-exported picture in response to the acquisition request. Since the server 104 needs to store the to-be-exported picture in the memory of the server after obtaining the to-be-exported picture, the server 104 also needs to obtain the current used memory of the server, so as to determine whether the system memory overflow occurs when the to-be-exported picture is stored according to the current used memory and the initial picture size of the to-be-exported picture.
[0066] In step 220, the total occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server is determined based on the initial picture size and the current used memory.
[0067] The total occupation ratio represents the proportion of the to-be-exported memory and the current used memory of the server to the total memory of the server.
[0068] In a specific implementation, since the computer allocates storage space in units of measurement, for example, 2 kb as a unit, and the initial picture size is 3 kb, two units need to be allocated, that is, 4 k of memory is needed. Therefore, the memory occupied by the to-be-exported picture when stored is often not equal to the initial picture size of the to-be-exported picture itself. Therefore, after obtaining the initial picture size of the to-be-exported picture, the memory required for exporting the to-be-exported picture needs to be determined based on the initial picture size, and then the proportion of the to-be-exported picture and the current used memory to the total memory of the server is determined based on the memory required for exporting the to-be-exported picture and the current used memory of the server, to obtain the total occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server.
[0069] In step 230, when the total occupation ratio is greater than a preset critical ratio, the picture compression processing is performed on the to-be-exported picture to obtain a compressed picture of the to-be-exported picture.
[0070] In a specific implementation, a critical proportion of occupied memory that the server can accommodate can be preset, for example, the critical proportion is set to 60%, which indicates that the proportion of the total memory occupied by the server cannot exceed 60%. To ensure that the total memory occupied by the server is within the preset critical proportion, after obtaining the total proportion of the total memory occupied by the to-be-exported picture and the current used memory, the total proportion can be compared with the preset critical proportion to determine whether the total proportion exceeds the preset critical proportion. More specifically, if it is determined that the total proportion is greater than the preset critical proportion, it indicates that the direct storage of the to-be-exported picture can cause the server to overflow, and therefore, the to-be-exported picture needs to be compressed to reduce the proportion of the total memory occupied by the to-be-exported picture. Conversely, if it is determined that the total proportion is not greater than the preset critical proportion, that is, the total proportion is less than or equal to the preset critical proportion, it indicates that the direct storage of the to-be-exported picture will not cause the server to overflow, and therefore, the to-be-exported picture does not need to be compressed.
[0071] In step 240, the compressed picture is sent to the terminal.
[0072] In a specific implementation, after obtaining the compressed picture, the server 104 can return the compressed picture to the terminal 102 through the interface of the server 104, so that the terminal 102 loads and displays the picture on the page of the terminal 102.
[0073] In the above picture processing method, the server obtains the initial size of the to-be-exported picture and the current used memory of the server in response to the acquisition request for the to-be-exported picture sent by the terminal, so as to determine the total proportion of the total memory occupied by the to-be-exported picture and the current used memory based on the initial picture size and the current used memory. Thus, whether the system memory will overflow when the to-be-exported picture is stored can be determined based on the total proportion and the preset critical proportion. If the total proportion is greater than the preset critical proportion, it indicates that the system memory can overflow, and therefore, the to-be-exported picture can be compressed to obtain a compressed picture of the to-be-exported picture, and the compressed picture is sent to the terminal. This method compresses the to-be-exported picture according to the initial picture size of the to-be-exported picture and the memory occupation of the server before the to-be-exported picture is exported, which realizes adaptive dynamic adjustment of the picture size and maximizes the use of server resources. The method can effectively avoid the inconvenience caused by the evasive measures taken by the conventional picture export, and does not need to set the picture file upload size limit or the fixed compression proportion of picture display.
[0074] In an example embodiment, the step 220 can be implemented by determining the total memory occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server based on the initial picture size of the to-be-exported picture and the current used memory, which includes: determining the memory required for exporting the to-be-exported picture based on the initial picture size of the to-be-exported picture; summing the memory required for exporting the to-be-exported picture and the current used memory to obtain the total memory occupation; and obtaining the ratio between the total memory occupation and the total memory of the server as the total memory occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server.
[0075] In a specific implementation, the initial picture size of the to-be-exported picture is S, the memory required for exporting the to-be-exported picture based on the initial picture size S is M1, wherein the actual memory M1 is slightly larger than S, the current used memory of the server is M2, and the total memory occupation of the to-be-exported picture and the current used memory can be represented as M1+M2. The total memory occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server can be represented as (M1+M2) / MA.
[0076] In the embodiment, the memory required for exporting the to-be-exported picture is determined based on the initial picture size of the to-be-exported picture, the memory required for exporting the to-be-exported picture and the current used memory are summed to obtain the total memory occupation, and the ratio between the total memory occupation and the total memory of the server is obtained as the total memory occupation ratio, so as to further compare the total memory occupation ratio with the preset critical ratio to determine whether to perform picture compression processing on the to-be-exported picture, thereby avoiding the overflow of the memory of the server.
[0077] Further, in an example embodiment, the memory required for exporting the to-be-exported picture based on the initial picture size of the to-be-exported picture includes: obtaining a preset memory adjustment ratio, wherein the memory adjustment ratio represents the ratio between the memory required for exporting the to-be-exported picture and the initial picture size of the to-be-exported picture; and obtaining the product between the initial picture size of the to-be-exported picture and the memory adjustment ratio as the memory required for exporting the to-be-exported picture.
[0078] The memory adjustment ratio represents the ratio between the memory required for exporting the to-be-exported picture and the initial picture size of the to-be-exported picture, i.e., the ratio between the space required for storing the to-be-exported picture and the picture size of the to-be-exported picture, and the memory adjustment ratio is greater than 1.
[0079] In a specific implementation, the memory adjustment ratio can be preset, for example, the memory adjustment ratio is set to 1.1, and the product of the initial picture size of the picture to be exported and the memory adjustment ratio is calculated as the memory required for exporting the picture to be exported, so that the memory required for exporting the picture to be exported is slightly larger than the initial picture size of the picture to be exported. For example, taking the memory adjustment increment of 1.1 as an example, if the initial picture size of the picture to be exported is 10 kb, the memory required for exporting the picture to be exported is 10 kb x 1.1 = 11 kb; if the initial picture size of the picture to be exported is 90 b, the memory required for exporting the picture to be exported is 90 b x 1.1 = 99 b.
[0080] Further, since the sizes of different pictures to be exported are different, a plurality of picture size intervals can also be preset, a corresponding memory adjustment ratio is set for each picture size interval, the target picture size interval corresponding to the picture to be exported is determined in the plurality of preset picture size intervals, the memory adjustment ratio corresponding to the target picture size interval is obtained as the target memory adjustment ratio corresponding to the picture to be exported, and the product between the initial picture size of the picture to be exported and the target memory adjustment ratio is obtained as the memory required for exporting the picture to be exported.
[0081] In another implementation, a memory adjustment increment value can also be set, and the sum of the initial picture size of the picture to be exported and the memory adjustment increment value is calculated as the memory required for exporting the picture to be exported, wherein the memory adjustment increment value can be a dimensionless value, and the unit thereof is determined according to the initial picture size of the picture to be exported. For example, if the memory adjustment increment is 2, if the initial picture size of the picture to be exported is 10 kb, the memory required for exporting the picture to be exported is 10 kb + 2 kb = 12 kb; if the initial picture size of the picture to be exported is 900 b, the memory required for exporting the picture to be exported is 900 b + 2 kb = 902 kb.
[0082] In the embodiment, the memory adjustment ratio is preset, so that the memory required for exporting the picture to be exported is determined based on the memory adjustment ratio and the initial picture size of the picture to be exported, thereby facilitating the determination of whether the storage of the picture to be exported will cause the overflow of the server memory.
[0083] In an exemplary embodiment, the picture compression processing on the picture to be exported in the step 230 to obtain the compressed picture can be implemented in the following manner: determining the picture compression ratio value of the picture to be exported based on the current used memory of the server, the total memory of the server and the preset critical ratio; and performing picture compression processing on the picture to be exported according to the picture compression ratio value to obtain the compressed picture.
[0084] The image compression ratio value represents the ratio between the size of the compressed image and the size of the image to be exported, that is, the ratio between the size of the compressed image and the size of the original image.
[0085] In practice, based on the relationship that the ratio of the total memory usage of the image to be exported to the total memory usage of the server is less than or equal to a critical ratio, the critical value of the memory required to export the image can be calculated to ensure that the server memory does not overflow when storing the image to be exported. The ratio of this critical value to the initial image size of the image to be exported is then used as the image compression ratio value of the image to be exported. Furthermore, the image to be exported can be compressed according to this image compression ratio value to obtain a compressed image.
[0086] For example, if we denote the memory required to export the image as M1, the server's currently used memory as M2, the server's total memory as MA, and the preset critical ratio as FM, then the total memory usage of the image to be exported and the currently used memory should not exceed the critical ratio, that is:
[0087] (M1+M2) / MA≤FM
[0088] Based on this relationship, we can obtain M1≤(FM×MA)-M2. Therefore, based on the server's currently used memory, the server's total memory, and the preset critical ratio, we can deduce the memory M1' required to export the image. Furthermore, we can obtain the ratio between the memory M1' required to export the image and the initial image size S of the image to be exported: M1' / S, which serves as the image compression ratio value of the image to be exported.
[0089] In this embodiment, the image compression ratio value of the image to be exported is determined based on the server's currently used memory, the server's total memory, and the preset critical ratio. This fully considers the server's memory usage, ensuring that the compressed image obtained by compressing according to this image compression ratio value will not overflow the server's memory.
[0090] In an exemplary embodiment, the image compression process for the image to be exported in step 230 above, to obtain a compressed image, can also be implemented in the following way: obtaining an initial image compression ratio value; compressing the image to be exported according to the initial image compression ratio value to obtain an initial compressed image; determining whether the total occupancy ratio of the initial compressed image and the currently used memory to the total memory of the server is greater than a critical ratio; if the total occupancy ratio is greater than the critical ratio, increasing the initial image compression ratio value according to a preset ratio to obtain a new image compression ratio value, and returning to the step of compressing the image to be exported, until the total occupancy ratio is no greater than the critical ratio, and a compressed image is obtained.
[0091] wherein the initial picture compression ratio value is within a preset compression ratio range, and the compression ratio range can be <50%-90%>.
[0092] In a specific implementation, when it is confirmed that the total occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server is greater than the preset critical ratio, the to-be-exported picture can be first compressed according to the initial picture compression ratio value (for example, 90%), to obtain an initial compressed picture, and then it is determined whether the total occupation ratio of the picture size of the initial compressed picture to the memory required for exporting and the current used memory of the server to the total memory of the server is greater than the preset critical ratio. The picture size of the initial compressed picture is obtained by multiplying the initial picture size by the initial picture compression ratio value. If it is determined that the total occupation ratio of the initial compressed picture to the total memory of the server is less than or equal to the preset critical ratio, it is indicated that the initial compressed picture will not cause the server memory to overflow when stored, and therefore, the initial compressed picture can be returned to the terminal as the final compressed picture. Otherwise, if it is determined that the total occupation ratio of the initial compressed picture to the total memory of the server is greater than the preset critical ratio, it is indicated that the initial compressed picture may cause the server memory to overflow when stored, and therefore, the picture compression ratio value needs to be reduced to reduce the picture size of the compressed picture. For example, the initial picture compression ratio value can be reduced from 90% to 80% according to a preset change amount of 10%, 80% is taken as a new picture compression ratio value, the to-be-exported picture is compressed according to the new picture compression ratio value to obtain a new compressed picture, the total occupation ratio of the memory required for exporting the new compressed picture and the current used memory of the server to the total memory of the server is calculated again, and it is determined whether the total occupation ratio is greater than the preset critical ratio. If it is still greater, the picture compression ratio value is reduced to 70% again, until the total occupation ratio obtained is not greater than the preset critical ratio, the final compressed picture is obtained, and the compressed picture is returned to the terminal for display. When the picture compression ratio value is reduced, it needs to be within a preset picture compression ratio range.
[0093] In this embodiment, the to-be-exported picture is compressed by gradually reducing the picture compression ratio value until the total occupation ratio obtained is not greater than the preset critical ratio, to obtain the final compressed picture, so as to ensure the clarity of the to-be-exported picture as much as possible while meeting the condition that the server memory does not overflow when the compressed picture is stored.
[0094] In an example embodiment, it also includes: when the total occupation ratio of the to-be-exported picture and the current used memory to the total memory of the server is not greater than the preset critical ratio, the to-be-exported picture is returned to the terminal.
[0095] In the embodiment, when the total proportion of the to-be-exported picture and the current used memory to the total memory of the server is not greater than the preset critical proportion, it indicates that the direct storage of the to-be-exported picture will not cause the memory overflow of the server, and therefore, the to-be-exported picture can be returned to the terminal directly for display without picture compression processing, so as to ensure the clarity of the to-be-exported picture displayed by the terminal.
[0096] In another embodiment, as shown in Figure 3 a picture processing method is provided, which includes the following steps:
[0097] In step 310, in response to the acquisition request of the to-be-exported picture sent by the terminal, the initial picture size of the to-be-exported picture and the current used memory of the server are acquired.
[0098] In step 320, the preset memory adjustment ratio is acquired, which represents the ratio between the memory required for exporting the to-be-exported picture and the initial picture size of the to-be-exported picture.
[0099] In step 330, the product of the initial picture size of the to-be-exported picture and the memory adjustment ratio is acquired as the memory required for exporting the to-be-exported picture.
[0100] In step 340, the sum of the memory required for exporting the to-be-exported picture and the current used memory is obtained as the occupied memory sum.
[0101] In step 350, the ratio between the occupied memory sum and the total memory of the server is acquired as the total proportion of the to-be-exported picture and the current used memory to the total memory of the server.
[0102] In step 360, when the total proportion of the to-be-exported picture and the current used memory to the total memory of the server is not greater than the preset critical proportion, the to-be-exported picture is returned to the terminal.
[0103] In step 370, when the total proportion is greater than the preset critical proportion, the picture compression ratio value of the to-be-exported picture is determined based on the current used memory of the server, the total memory of the server and the preset critical proportion.
[0104] In step 380, the to-be-exported picture is subjected to picture compression processing according to the picture compression ratio value, and a compressed picture is obtained.
[0105] In step 390, the compressed picture is sent to the terminal.
[0106] The picture processing method provided in the application dynamically adjusts the picture resource display size (i.e. the size of the picture after compression) based on the available memory (JVM virtual machine memory). The picture resource is compressed according to the memory condition during computer processing, and the compressed picture file stream is written into a picture file and returned to the front-end page through an interface for display. The export of picture data each time is based on the available memory of the server, and the compression ratio in the picture processing process is dynamically adjusted based on the available memory, so that the system resources are maximized. Not only can the system memory overflow be effectively avoided, but also the problem of sometimes delay in rendering large pictures by the front-end browser can be solved, and the user experience in the case of more system picture resources is greatly improved.
[0107] In one embodiment, for the convenience of those skilled in the art to understand the embodiments of the application, the following will be described in conjunction with specific examples of the accompanying drawings. Referring to Figure 4 , the overall structure block diagram of the system for implementing the picture processing method of the application comprises a picture export initialization device 410, a picture export dynamic adjustment device 420 and a picture export device 430, wherein
[0108] The picture export initialization device 410 is configured to set and read the related initial parameters of picture export.
[0109] The picture export dynamic adjustment device 420 is configured to calculate and adjust the compression ratio of the picture and the actual export size of the picture according to the current memory usage of the server, in combination with the picture export memory occupation condition and the picture compression ratio range interval.
[0110] The picture export device 430 exports the actual data of the picture according to the calculated compression ratio, and judges whether the picture is compressed successfully after the export.
[0111] Referring to Figure 4.1 , the structure block diagram of the picture export initialization device 410 of the application comprises a picture file initial calculation unit 11 and a memory critical control initial unit 12, wherein
[0112] The picture file initial calculation unit 11 is configured to read the original size of the picture, the default compression ratio during export, and the ratio interval allowed for picture compression, for example, (50%-90%).
[0113] The memory critical control initial unit 12 is configured to set the critical proportion FM of the server memory usage during the picture export process, such as 60%.
[0114] Referring to Figure 4.2 , the structure block diagram of the picture export dynamic adjustment device 420 of the application comprises a picture memory calculation unit 21, a memory size acquisition unit 22, an export memory occupation calculation unit 23 and a picture export size adjustment unit 24, wherein
[0115] The picture memory calculating unit 21 is configured to calculate the memory space required for exporting the current picture file according to the original picture size of the picture.
[0116] The memory size obtaining unit 22 is configured to obtain the total memory size of the server and the current memory occupation of the server, i.e., the used memory size of the server.
[0117] The export memory occupation calculating unit 23 is configured to calculate the sum of the memory occupation of the server and the memory required for exporting the current picture according to the used memory of the server obtained by the memory occupation obtaining unit 22 and the memory required for exporting the current picture calculated by the picture memory calculating unit 21.
[0118] The picture export size adjusting unit 24 is configured to compare the sum of the memory occupation calculated by the export memory occupation calculating unit 23 with the total memory of the server, and if the ratio of the sum of the memory occupation to the total memory exceeds a preset critical ratio, the picture compression ratio is reduced according to the algorithm of equal proportion reduction, i.e., the actual export size of the picture is reduced, to obtain a new actual export size of the picture, which is transmitted to the picture export device 430.
[0119] Reference Figure 4.3 FIG. 4 is a structural block diagram of the picture export device 430 of the present application, which comprises a picture export verification unit 31 and a picture data export unit 32.
[0120] The picture export verification unit 31 is configured to verify the size of the file object exported this time, and obtain the actual export picture file size. If the actual export picture file size is less than or equal to the initial file size, it indicates that the picture export dynamic adjustment device is processed normally, and the next picture export can be performed. Otherwise, the picture export dynamic adjustment device is processed abnormally, the terminal picture export process is terminated, and the picture export is abnormal.
[0121] The picture data export unit 32 is configured to write the calculated compressed file stream data into the file object to perform file export.
[0122] Reference Figure 5 FIG. 5 is a picture export processing flowchart based on the available memory dynamic adjustment picture compression ratio of the present application, which comprises the following steps.
[0123] In step 501, the user clicks the page jump loading to start the picture export processing.
[0124] In step 502, the export flow reads the initial file size S, the default picture compression ratio value R, and the preset compression ratio interval [MIN, MAX] from the picture file initial size calculating unit 11 of the picture export initialization device 410, and transmits these parameters to the picture export dynamic adjustment device 420, wherein R is located in the compression ratio interval.
[0125] Step 503: After the calculation processing, the picture export dynamic adjustment device 420 returns the actual size N of the picture to be exported this time, the actual exported picture file stream data D, the memory occupation ratio F1 of this picture export, and transmits N and D to the picture export device 430.
[0126] Step 504: The picture export verification unit 31 of the picture export device 430 compares the obtained actual exported file size N with the initial file size S. If N≤S, the dynamic adjustment process is normal, and the next export can be performed. Otherwise, the dynamic adjustment process is abnormal, the picture export is abnormal, and the export process is interrupted.
[0127] Step 505: The picture data export unit 32 of the picture export device 430 writes the obtained actual picture file stream data D into a file and returns it to the requester, and the export process is completed.
[0128] Reference Figure 6 The processing flowchart of the picture export dynamic adjustment device 420 includes the following steps:
[0129] Step 601: The picture memory calculation unit 21 estimates and calculates the memory occupation size M1 required for this picture export S according to the initial size S of the picture file to be exported this time.
[0130] Step 602: The memory size acquisition unit 22 acquires the current available memory of the server to obtain the total memory size MA and the used memory size M2 of the server.
[0131] Step 603: The export memory occupation calculation unit 23 calculates the proportion F1 of the memory M1 required for this picture export to the total memory MA and the proportion F2 of the currently used memory M2 to the total memory MA, and takes the sum F1+F2 of the two proportions as the total occupation proportion FA.
[0132] Step 604: The picture export dynamic adjustment device 420 judges whether the total occupation proportion FA is greater than the preset critical proportion FM (such as 60%). If yes, the picture export dynamic adjustment device 420 does not adjust the imported picture export size S this time. If no, it goes to step 605.
[0133] Step 605: The picture export size adjustment unit of the picture export dynamic adjustment device 420 calculates the compression ratio R of this picture export n and the compressed picture file stream data D. R n The calculation method is: calculate the maximum memory usage critical value M3=FM*MA, calculate the remaining memory: M4=M3-M2, and the compression ratio is the ratio of the available remaining memory and the estimated picture initial memory: Rn = M4 / M1, if R n < R, then R n = R, if R n > R and is greater than a preset maximum compression ratio interval MAX, it is prompted that the picture exceeds the preset maximum compression ratio interval, the picture display resolution will be reduced, and the processed picture export size N is obtained, N = S x R n .
[0134] Step 606: The actual size N of the current picture export is calculated after dynamic adjustment, the file stream data is read from the picture storage location and compressed according to the calculated compression ratio R n to obtain the compressed file stream data D.
[0135] The export device for dynamically adjusting the picture export compression ratio based on the available JVM memory is implemented, which realizes that the picture export can be dynamically adjusted according to the JVM memory usage, and has the following advantages: (1) the picture export process can be dynamically adjusted according to the use of server memory resources, which can reasonably utilize the server memory resources and avoid memory overflow caused by large picture file export; (2) it can effectively avoid the inconvenience caused by the evasive means adopted by the conventional picture export, and does not need to set the picture file upload size limit or the fixed compression ratio of picture display.
[0136] It should be understood that although each step in the flowchart involved in each embodiment as described above is displayed in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless otherwise stated herein, the execution of these steps has no strict sequence limitation, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowchart involved in each embodiment as described above can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be alternately or alternately executed with at least part of other steps or steps or stages in other steps.
[0137] Based on the same inventive concept, the embodiments of the present application also provide a picture processing device for implementing the picture processing method as described above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more picture processing device embodiments provided below can refer to the limitations of the picture processing method in the above text, which will not be repeated here.
[0138] In one embodiment, as Figure 7As shown, a picture processing apparatus is provided, comprising: an acquisition module 710, a determination module 720, a compression module 730 and a sending module 740, wherein:
[0139] The acquisition module 710 is configured to acquire an initial picture size of a picture to be exported and a current used memory of a server in response to an acquisition request of the picture to be exported sent by a terminal.
[0140] The determination module 720 is configured to determine a total occupancy ratio of the picture to be exported and the current used memory to a total memory of the server based on the initial picture size and the current used memory.
[0141] The compression module 730 is configured to perform picture compression processing on the picture to be exported to obtain a compressed picture of the picture to be exported when the total occupancy ratio is greater than a preset critical ratio.
[0142] The sending module 740 is configured to send the compressed picture to the terminal.
[0143] In an embodiment, the determination module 720 is specifically configured to determine a required memory for exporting the picture to be exported based on the initial picture size of the picture to be exported; perform summation processing on the required memory for exporting the picture to be exported and the current used memory to obtain an occupancy memory sum; and acquire a ratio between the occupancy memory sum and a total memory of the server as the total occupancy ratio of the picture to be exported and the current used memory to the total memory of the server.
[0144] In an embodiment, the determination module 720 is further configured to acquire a preset memory adjustment ratio; the memory adjustment ratio represents a ratio between the required memory for exporting the picture to be exported and the initial picture size of the picture to be exported; and acquire a product between the initial picture size of the picture to be exported and the memory adjustment ratio as the required memory for exporting the picture to be exported.
[0145] In an embodiment, the compression module 730 is specifically configured to determine a picture compression ratio value of the picture to be exported based on the current used memory of the server, the total memory of the server and the preset critical ratio; and perform picture compression processing on the picture to be exported according to the picture compression ratio value to obtain the compressed picture.
[0146] In an embodiment, the compression module 730 is further configured to acquire an initial picture compression ratio value; perform picture compression processing on the picture to be exported according to the initial picture compression ratio value to obtain an initial compressed picture; determine whether a total occupancy ratio of the initial compressed picture and the current used memory to the total memory of the server is greater than the critical ratio; if the total occupancy ratio is greater than the critical ratio, reduce the initial picture compression ratio value to obtain a new picture compression ratio value, and return to the step of performing picture compression processing on the picture to be exported until the total occupancy ratio is not greater than the critical ratio to obtain the compressed picture.
[0147] In an embodiment, the sending module 740 is further configured to return the picture to be exported to the terminal when the total proportion of the picture to be exported and the current used memory to the total memory of the server is not greater than a preset critical proportion.
[0148] The modules in the picture processing apparatus can be implemented by software, hardware, or a combination thereof. The modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in a computer device in software form, so as to be invoked and executed by a processor to perform operations corresponding to the modules.
[0149] In an embodiment, a computer device is provided, which can be a server. An internal structure diagram of the computer device can be as shown in FIG. 8. Figure 8 The computer device includes a processor, a memory, and a network interface connected by a system bus. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store data in a picture processing process. The network interface of the computer device is configured to communicate with an external terminal through a network connection. The computer program is executed by the processor to implement a picture processing method.
[0150] Those skilled in the art can understand that the structure shown in FIG. 8 is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. A specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components. Figure 8 In an embodiment, a computer device is provided, which includes a memory and a processor. The memory stores a computer program. The processor executes the computer program to implement the steps in the above method embodiments.
[0151] In an embodiment, a computer readable storage medium is provided, which stores a computer program. The computer program is executed by a processor to implement the steps in the above method embodiments.
[0152] In an embodiment, a computer program product is provided, which includes a computer program. The computer program is executed by a processor to implement the steps in the above method embodiments.
[0153]
[0154] It should be noted that the picture processing method and device, computer device, computer readable storage medium and computer program product provided in the present application can be used for picture compression in the financial field, and can also be applied to any field other than the financial field. The application does not specifically limit the application field.
[0155] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties.
[0156] It can be understood by those skilled in the art that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. Any reference to a memory, database or other medium used in the embodiments provided in the present application can include at least one of a non-volatile and volatile memory. The non-volatile memory can include a read-only memory (Read-Only Memory, ROM), a magnetic tape, a floppy disk, a flash memory, an optical memory, a high-density embedded non-volatile memory, a resistive memory (ReRAM), a magnetoresistive random access memory (Magnetoresistive Random Access Memory, MRAM), a ferroelectric memory (Ferroelectric Random Access Memory, FRAM), a phase change memory (Phase Change Memory, PCM), a graphene memory, etc. The volatile memory can include a random access memory (Random Access Memory, RAM) or an external cache memory, etc. As an illustration but not limitation, the RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0157] Any technical features in the above embodiments can be combined, and for the sake of brevity, not all possible combinations are described above, however, as long as the combinations of technical features do not have contradictions, they shall be considered within the scope of the present disclosure.
[0158] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it shall not be understood as a limitation on the patent scope of the present application. It shall be pointed out that, for ordinary skilled persons in the art, several modifications and improvements can be made without departing from the concept of the present application, and these shall be within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.
Claims
1. A picture processing method, characterized by, The method comprises: in response to a terminal sending an acquisition request for a picture to be exported, acquiring an initial picture size of the picture to be exported and current used memory of a server, wherein the picture to be exported represents a picture that needs to be exported to the terminal for display by the server; based on the initial picture size and the current used memory, determining a total occupancy ratio of the picture to be exported and the current used memory to total memory of the server; when the total occupancy ratio is greater than a preset critical ratio, performing picture compression processing on the picture to be exported to obtain a compressed picture of the picture to be exported; the picture compression processing on the picture to be exported comprises: acquiring an initial picture compression ratio value; performing picture compression processing on the picture to be exported according to the initial picture compression ratio value to obtain an initial compressed picture; determining whether a total occupancy ratio of the initial compressed picture and the current used memory to the total memory of the server is greater than the critical ratio; if the total occupancy ratio is greater than the critical ratio, reducing the initial picture compression ratio value to obtain a new picture compression ratio value, and returning to the step of performing picture compression processing on the picture to be exported until the total occupancy ratio is not greater than the critical ratio, and the compressed picture is obtained; sending the compressed picture to the terminal.
2. The method of claim 1, wherein, The determination of the total occupancy ratio of the picture to be exported and the current used memory to the total memory of the server based on the initial picture size and the current used memory comprises: based on the initial picture size of the picture to be exported, determining memory required for exporting the picture to be exported; performing sum processing on the memory required for exporting the picture to be exported and the current used memory to obtain an occupancy sum; acquiring a ratio between the occupancy sum and the total memory of the server as the total occupancy ratio of the picture to be exported and the current used memory to the total memory of the server.
3. The method of claim 2, wherein, The determination of the memory required for exporting the picture to be exported based on the initial picture size of the picture to be exported comprises: acquiring a preset memory adjustment ratio; the memory adjustment ratio represents a ratio between the memory required for exporting the picture to be exported and the initial picture size of the picture to be exported; acquiring a product between the initial picture size of the picture to be exported and the memory adjustment ratio as the memory required for exporting the picture to be exported.
4. The method of claim 1, wherein, The picture compression processing on the picture to be exported to obtain a compressed picture comprises: based on the current used memory of the server, the total memory of the server and the preset critical ratio, determining a picture compression ratio value of the picture to be exported; performing picture compression processing on the picture to be exported according to the picture compression ratio value to obtain the compressed picture.
5. The method of claim 1, wherein, The method further comprises: when the total occupancy ratio of the picture to be exported and the current used memory to the total memory of the server is not greater than the preset critical ratio, returning the picture to be exported to the terminal.
6. An image processing apparatus characterized by comprising: The device comprises: An acquisition module is configured to acquire an initial picture size of a picture to be exported and a current used memory of a server in response to an acquisition request of the picture to be exported sent by a terminal, wherein the picture to be exported represents a picture that needs to be exported to the terminal by the server for display; A determination module is configured to determine a total occupancy ratio of the picture to be exported and the current used memory to a total memory of the server based on the initial picture size and the current used memory; A compression module is configured to perform picture compression processing on the picture to be exported to obtain a compressed picture of the picture to be exported when the total occupancy ratio is greater than a preset critical ratio. The compression module is further configured to acquire an initial picture compression ratio value, perform picture compression processing on the picture to be exported according to the initial picture compression ratio value to obtain an initial compressed picture, and determine whether a total occupancy ratio of the initial compressed picture and the current used memory to the total memory of the server is greater than the critical ratio. If the total occupancy ratio is greater than the critical ratio, the initial picture compression ratio value is decreased to obtain a new picture compression ratio value, and the picture compression processing on the picture to be exported is returned until the total occupancy ratio is not greater than the critical ratio, and the compressed picture is obtained. A sending module is configured to send the compressed picture to the terminal. 7.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-6 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the method in any one of claims 1 to 5.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 5.
9. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 5.
Citation Information
Patent Citations
Image processing system, method and apparatus
CN108347451A
Data paging export method, device, computer equipment and storage medium
CN110413978A