Method, device and storage medium for compressing pictures
By performing image processing on the compressed pictures, compressed pictures compatible with the mobile terminal are generated according to the set parameters, the problem of difficult to meet the requirements of compression, size control and clarity in the prior art is solved, and the compatibility of the mobile terminal is improved.
Patent Information
- Application Number
- CN202111442091.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2041-11-30
AI Technical Summary
The prior art is difficult to meet the requirements of compressing pictures according to set parameters, controlling picture sizes and ensuring picture clarity. The processed pictures are not compatible in some mobile terminals.
By determining the first picture to be compressed and its target parameter value, and image processing of the first picture according to the target parameter value, a second picture corresponding to the target parameter value is generated to meet the compression, size control and clarity requirements and improve mobile compatibility.
The requirements of compressing pictures according to the set parameters, controlling picture size and ensuring clarity are achieved, while ensuring that the processed pictures are compatible in the mobile terminal, solving the incompatibility problems existing in the prior art.
Smart Images

Figure CN114283057B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device and storage medium for compressing pictures. Background Art
[0002] At present, in order to meet the needs of users who frequently use pictures, designers often develop software with the purpose of compressing the space occupied by pictures and adjusting the size of pictures. Therefore, designers have developed picture compression processing operation tools.
[0003] However, when using existing image compression technology to compress images, it is often impossible to simultaneously meet the requirements of compressing images according to set parameters, controlling image size, and ensuring image clarity. In addition, existing image compression technology also has the problem of limited export image formats and incompatibility of processed images in some mobile terminals.
[0004] Currently, no effective solution has been proposed for the technical problems that the above-mentioned prior art cannot meet the requirements of compressing images according to set parameters, controlling image size and ensuring image clarity, and the processed images are incompatible with some mobile terminals. Summary of the invention
[0005] The embodiments of the present disclosure provide a method, device and storage medium for compressing pictures, so as to at least solve the technical problems existing in the prior art that the requirements of compressing pictures according to set parameters, controlling picture size and ensuring picture clarity cannot be met at the same time, and the processed pictures are incompatible with some mobile terminals.
[0006] According to one aspect of an embodiment of the present disclosure, a method for compressing an image is provided, including: determining a first image to be compressed and a target parameter value, wherein the target parameter value is a maximum restricted image parameter value of the compressed first image; performing image processing on the first image; and generating a second image corresponding to the target parameter value.
[0007] According to another aspect of an embodiment of the present disclosure, a storage medium is further provided, the storage medium including a stored program, wherein when the program is running, a processor executes any one of the methods described above.
[0008] According to another aspect of an embodiment of the present disclosure, a device for compressing an image is also provided, including: a determination module for determining a first image to be compressed and a target parameter value, wherein the target parameter value is an image information value of the compressed first image; a processing module for performing image processing on the first image; and a generation module for generating a second image corresponding to the target parameter value.
[0009] According to another aspect of an embodiment of the present disclosure, a device for compressing an image is also provided, including: a processor; and a memory connected to the processor, for providing the processor with instructions for processing the following processing steps: determining a first image to be compressed and a target parameter value, wherein the target parameter value is an image information value of the compressed first image; performing image processing on the first image; and generating a second image corresponding to the target parameter value.
[0010] In the embodiment of the present disclosure, by determining the first picture and the target parameter value, and performing image processing on the first picture according to the target parameter value, it is possible to achieve the technical effect of simultaneously meeting the requirements of compressing the picture according to the set parameters, controlling the picture size, and ensuring the picture clarity, and the pictures in the mobile terminal are compatible. This solves the technical problem that the requirements of compressing the picture according to the set parameters, controlling the picture size, and ensuring the picture clarity, which exists in the prior art, cannot be met at the same time, and the pictures in some mobile terminals are not compatible. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The drawings described herein are used to provide a further understanding of the present disclosure and constitute a part of the present application. The illustrative embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation on the present disclosure. In the drawings:
[0012] Figure 1 is a hardware structure block diagram of a computing device for implementing the method according to Embodiment 1 of the present disclosure;
[0013] Figure 2 is a schematic diagram of a system for compressing pictures according to Embodiment 1 of the present disclosure;
[0014] Figure 3 is a flowchart of a method for compressing a picture according to the first aspect of Embodiment 1 of the present disclosure;
[0015] Figure 4 is a schematic diagram of an interface of a terminal device for inputting a first picture and a target parameter value according to the first aspect of embodiment 1 of the present disclosure;
[0016] Figure 5a is a schematic diagram of an interface of a first picture set on a canvas panel according to the first aspect of Embodiment 1 of the present disclosure;
[0017] Figure 5b is a schematic diagram of an interface of a first image after rotation and set on a canvas panel according to the first aspect of Embodiment 1 of the present disclosure;
[0018] Figure 6 is a schematic diagram of a device for compressing pictures according to Embodiment 2 of the present disclosure; and
[0019] Figure 7 It is a schematic diagram of the device for compressing pictures according to Embodiment 3 of the present disclosure. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only embodiments of a part of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of the present disclosure.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0022] First, some nouns or terms that appear in the process of describing the embodiments of the present disclosure are subject to the following explanations:
[0023] Image type: image type.
[0024] Canvas drawing board: Canvas drawing board is also a heavyweight drawing board.
[0025] Blob type: Binary Large Object, a container that can store binary files.
[0026] Example 1
[0027] According to this embodiment, an embodiment of a method for compressing a picture is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0028] The method embodiment provided in this embodiment can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Figure 1FIG. 1 shows a hardware structure block diagram of a computing device for implementing a method for compressing pictures. Figure 1 As shown, the computing device may include one or more processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory for storing data, and a transmission device for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0029] It should be noted that the one or more processors and / or other data processing circuits described above may generally be referred to herein as "data processing circuitry". The data processing circuitry may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuitry may be a single independent processing module, or may be incorporated in whole or in part into any of the other components of the computing device. As involved in the embodiments of the present disclosure, the data processing circuitry acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0030] The memory can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to a method for compressing pictures in the embodiment of the present disclosure. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, a method for compressing pictures of the above-mentioned application program. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computing device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0031] The transmission device is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computing device. In one example, the transmission device includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device can be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
[0032] The display may be, for example, a touch screen liquid crystal display (LCD) that may enable a user to interact with a user interface of the computing device.
[0033] It should be noted that, in some optional embodiments, the above Figure 1 The computing device shown may include hardware elements (including circuits), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware elements and software elements. Figure 1 This is merely one example of a particular embodiment and is intended to illustrate the types of components that may be present in the computing devices described above.
[0034] Figure 2 is a schematic diagram of a system for compressing pictures according to this embodiment. Figure 2 As shown, the system includes: a terminal device 100 and a server 200. The terminal device 100 is provided with a client program for compressing images, so that the user can receive the original image input by the user and the target parameter value required to generate the target image through the client program, and the client program compresses the original image according to the received target parameter value required to generate the target image to form the target image. The user uploads the target image to the server 200 through the terminal device 100, and the server 200 further processes the target image. It should be noted that the terminal device 100 and the server 200 in the system can both be applied to the hardware structure described above.
[0035] Under the above operating environment, according to the first aspect of this embodiment, a method for compressing a picture is provided. The method comprises: Figure 2 The terminal device 100 shown in FIG. Figure 3 A schematic diagram showing the process of the method is shown in FIG. Figure 3 As shown, the method includes:
[0036] S302: Determine a first picture to be compressed and a target parameter value, wherein the target parameter value is a picture information value of the compressed first picture;
[0037] S304: performing image processing on the first picture; and
[0038] S306: Generate a second picture corresponding to the target parameter value.
[0039] Specifically, according to the technical solution described in this embodiment, the user can convert the first picture input by the user into a second picture by performing a compression processing operation on the picture on the terminal device 100, wherein the first picture is the original picture and the second picture is the compressed target picture. Figure 4 The schematic diagram of the interface for inputting the first image to be uploaded and the target parameter value displayed by the terminal device 100 is shown. The interface may be popped up by the terminal device 100 in response to the trigger operation of the user requiring the compression processing operation to be performed on the first image. Figure 4 The interface shown compresses the first picture.
[0040] refer to Figure 4 As shown, the interface for uploading the original image and the target parameter value includes the following controls: an image control and a target parameter value control.
[0041] The user can upload the first picture that needs to be compressed to the terminal device 100 through the picture control.
[0042] The user can input the set target parameter value into the terminal device 100 through the target parameter value control. For example, the user can input the maximum width value in the width value control, or the maximum height value in the height value control, the maximum aspect ratio in the aspect ratio control, and the maximum storage value in the storage value space. The terminal device 100 limits the maximum width value, maximum height value, maximum aspect ratio, and maximum storage value allowed for the first picture through the above target parameter values input by the user.
[0043] Furthermore, the user can fill in the target parameter information value so that the terminal device 100 can perform a compression processing operation on the original image and generate a target image according to the target parameter information filled in by the user.
[0044] Thus, the user can upload the original image and input the target parameter value through the interface. After entering the above information, the user can click the "Upload" button. After receiving the first image uploaded by the user and the target parameter value, the terminal device 100 parses the first image. After that, the terminal device 100 parses the first image and outputs the original parameter value of the first image. Among them, the original parameter value includes the width value of the first image, the height value of the first image, the aspect ratio of the first image, the format of the image, and the quality of the image, etc. (S302).
[0045] Then, the terminal device 100 performs image processing on the first image according to the target parameter value input by the user (S304). The operation of the terminal device 100 performing image processing on the first image includes: comparing the original parameter value of the first image parsed by the terminal device 100 with the target parameter value input by the user, setting the width value and height value of the second image according to the comparison result, and performing compression processing.
[0046] Thus, the terminal device 100 generates a second picture corresponding to the target parameter value (S306).
[0047] The terminal device 100 displays the generated second image to the user. If the second image meets the user's requirements, the user can upload the second image to the server 200 through the terminal device 100 and the server 200 can further process the second image; if the second image does not meet the user's requirements, the user can compress the second image again.
[0048] As described in the background technology, the existing image compression technology often cannot simultaneously meet the requirements of compressing images according to set parameters, controlling image size, and ensuring image clarity. In addition, the existing image compression technology also has the problem of few export image formats and the incompatibility of processed images in some mobile terminals.
[0049] In view of the above-mentioned technical problems, through the technical solution of this embodiment, after the terminal device 100 receives the first picture uploaded by the user and the target parameter value, it parses the first picture to obtain the original parameter value of the first picture. Then, the terminal device 100 compares the original parameter value with the target parameter value, and performs compression processing and rotation processing on the first picture according to the target parameter value, thereby generating a second picture. Finally, the terminal device 100 displays the generated second picture to the user. Therefore, when the angle of the first picture deviates, the terminal device 100 will correct the angle of the first picture and rotate the picture to the correct position, thereby avoiding the problem of automatic rotation of the picture due to the compatibility problem of the terminal device and improving the compatibility of the mobile terminal.
[0050] Thus, the technical solution can achieve the technical effect of simultaneously meeting the requirements of compressing the image according to the set parameters, controlling the image size, and ensuring that the image is not deformed, and the processed image is compatible with the images in the mobile terminal by determining the first image and the target parameter value, and performing image processing on the first image according to the target parameter value. This solves the technical problem that the requirements of compressing the image according to the set parameters, controlling the image size, and ensuring the image clarity, and the processed image are not compatible with some mobile terminals in the prior art.
[0051] Optionally, determining a first image to be compressed and a target parameter value, wherein the target parameter value is a maximum limit image parameter value of the first image after compression, comprises: parsing the first image, obtaining an original parameter value of the first image, wherein the original parameter value is an image information value of the first image; and determining the target parameter value, and performing image processing on the first image according to the target parameter value.
[0052] Specifically, after the terminal device 100 receives the first picture uploaded by the user, it will parse the first picture to obtain the original parameter values of the first picture. Among them, the original parameter values of the first picture include: width value, height value and aspect ratio, etc. Afterwards, after receiving the target parameter value input by the user, the terminal device 100 will perform image compression processing operations on the first picture according to the target parameter value. Among them, the target parameter values include: maximum width value, maximum height value, maximum aspect ratio and maximum storage value, etc. Afterwards, the terminal device 100 will also analyze whether the first picture needs to be changed in position based on the position information of the first picture. More specifically, the terminal device 100 will determine whether the first picture needs to be rotated. When the angle of the first picture deviates, the terminal device 100 will rotate the first picture, thereby changing the position information of the first picture, solving the problem of deviation in the angle of the picture caused by compatibility issues.
[0053] Thus, by parsing the original parameter values of the first image, determining the target parameter values, and rotating the generated second image, it is possible to achieve the technical effect of satisfying the user's compression processing operation on the first image according to the preset target parameters and solving the problem of incompatibility of images in some mobile terminals.
[0054] Optionally, the operation of performing image processing on the first picture includes: comparing the original parameter value with the target parameter value; and when the original parameter value is different from the target parameter value, performing image processing on the first picture to generate the second picture.
[0055] Specifically, after the terminal device 100 parses the first image uploaded by the user and obtains the target parameter value uploaded by the user, it will compare the original parameter value generated after parsing the first image with the target parameter value. If the original parameter value is the same as the target parameter value, it means that the first image meets the user's needs, and the terminal device 100 does not need to perform image processing on the first image; if the original parameter value is different from the target parameter value, it means that the first image does not meet the user's needs, and the terminal device 100 needs to perform image processing on the first image. The situation where the original parameter value is different from the target parameter value includes: the height value in the original parameter value is less than the maximum height value in the target parameter value, the width value in the original parameter value is less than the maximum width value in the target parameter value, and the aspect ratio in the original parameter value is less than the maximum aspect ratio in the target parameter value.
[0056] After performing image processing on the first image, the terminal device 100 generates a second image corresponding to the target parameter value. The image processing may be a compression processing operation and a rotation processing on the first image. Thus, the terminal device 100 can judge whether the first image input by the user needs to be image processed by comparing the original parameter value with the target parameter value, thereby avoiding the operation of processing images that do not need image processing, improving the efficiency of processing images, and saving time costs.
[0057] Optionally, the method further includes: when the first image is of Image type, initializing a canvas drawing board according to a target parameter value configuration, wherein the first image is set on the canvas drawing board.
[0058] Specifically, before processing the first image, the terminal device 100 needs to determine whether the first image is of the Image type. If the first image is of the Image type, the terminal device 100 initializes the canvas drawing board according to the target parameter value configuration, and sets the first image on the canvas drawing board. If the first image is not of the Image type, the terminal device 100 does not perform a compression processing operation on the first image. Therefore, before compressing the first image, the operation of determining whether the first image is of the Image type achieves the technical effect of saving the time cost of the compression processing operation.
[0059] Optionally, setting target parameter values and performing image processing on the first picture according to the target parameter values includes: setting a maximum storage value, a maximum width value, a maximum height value and a maximum aspect ratio for compressing the first picture; and rotating the compressed first picture to generate a second picture when the positions of the first picture and the compressed first picture are different.
[0060] Specifically, after the terminal device 100 parses the first image and generates the original parameter value, it determines the target parameter value input by the user. The specific operation of determining the target parameter value is to set the maximum storage value, maximum width value, maximum height value and maximum aspect ratio for compressing the first image. And the maximum storage value, maximum width value, maximum height value and maximum aspect ratio are the maximum values that the storage capacity, width, height and aspect ratio can reach when the terminal device 100 performs a compression processing operation on the first image. For example, the maximum storage value of the second image generated after compression by the terminal device 100 is set to 10M, the maximum width value is set to 1200 and the maximum height value is set to 900. And, after the terminal device 100 determines the maximum storage value, the maximum width value and the maximum height value and performs a compression processing operation on the first image, it is determined whether the positions of the first image and the second image are the same. For example, if the second image obtained after the terminal device 100 compresses the first image is rotated, it is determined that the positions of the first image and the second image are not the same, so that the second image is rotated. Thus, setting the maximum limit value for the compression processing operation on the first image and the rotation processing operation on the second image achieves the technical effect of meeting the user's demand for image compression, ensuring the clarity of the compressed image, and solving the compatibility problem of the image on some mobile terminals.
[0061] Optionally, the operation of comparing the original parameter value with the target parameter value includes: when the width value of the first image is greater than the maximum width value set by the target parameter value and / or the height value of the first image is greater than the maximum height value set by the target parameter value, determining whether the aspect ratio of the first image is greater than the aspect ratio set by the target parameter value; and when the width value of the first image is less than the maximum width value set by the target parameter value and / or the height value of the first image is less than the maximum height value set by the target parameter value, setting the canvas drawing board size according to the width value and height value set for the first image.
[0062] Specifically, after setting the canvas drawing board, the terminal device 100 compares the width value and the height value in the original parameter value and the target parameter value respectively. When the width value in the original parameter value of the first picture is greater than the maximum width value set by the target parameter value and / or the height value in the original parameter value of the first picture is greater than the maximum height value set by the target parameter value, the terminal device 100 further determines whether the aspect ratio in the original parameter value of the first picture is greater than the maximum aspect ratio set by the target parameter value. When the width value in the original parameter value of the first picture is less than the maximum width value set by the target parameter value and / or the height value in the original parameter value of the first picture is less than the maximum height value set by the target parameter value, the canvas drawing board size is set according to the width value and the height value in the original parameter value of the first picture. For example, the width value of the first picture is 900, and the maximum width value set by the target parameter value is 800. Then, the terminal device 100 needs to further determine whether the aspect ratio in the original parameter value of the first picture is greater than the maximum aspect ratio set by the target parameter value.
[0063] Optionally, the operation of comparing the original parameter value with the target parameter value also includes: when the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value, using the maximum width value set by the target parameter value as the width value of the second picture and using the product of the maximum width value set by the target parameter value and the aspect ratio of the first picture as the height value of the second picture; and when the aspect ratio of the first picture is less than the maximum aspect ratio set by the target parameter value, using the maximum height value set by the target parameter value as the height value of the second picture and using the product of the maximum height value set by the target parameter value and the aspect ratio of the first picture as the width value of the second picture.
[0064] Specifically, after the terminal device 100 compares the width value and the height value in the original parameter value with the maximum width value and the maximum height value in the target parameter value, it is also necessary to compare the aspect ratio in the original parameter value with the maximum aspect ratio in the target parameter value. If the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value, then the width value of the second picture is the maximum width value in the target parameter value, and the height value of the second picture is the product of the maximum width value of the target parameter value and the aspect ratio of the first picture. For example, the aspect ratio of the first picture is 1.5, and the aspect ratio set by the target parameter value is 1.3. Then, the width value of the second picture is the width value set by the target parameter value, and the height value of the second picture is the product of the width value of the second picture and the aspect ratio of the first picture.
[0065] Optionally, the method further includes: when determining the width value and the height value of the pre-generated second image, setting the canvas drawing board size according to the width value and the height value of the pre-generated second image.
[0066] Specifically, the first picture is set on the canvas drawing board and the size of the second picture generated by the compression processing operation of the first picture is the same as the size of the canvas drawing board. The terminal device 100 determines whether the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value and sets the width value and height value of the canvas drawing board according to the judgment result. For example, the aspect ratio of the first picture is 1.5, and the maximum aspect ratio set by the target parameter value is 1.3. The width value of the first picture is 1200, and the maximum width value set by the target parameter value is 900. If the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value, the width value of the canvas drawing board with the first picture is the maximum width value set by the target parameter value, and the height value is the product of the aspect ratio of the first picture and the maximum width value set by the target parameter value. Then the width value of the canvas drawing board with the second picture calculated by the terminal device 100 is 900, and the height value is 1350.
[0067] Optionally, when the positions of the first image and the canvas drawing board are different, the canvas drawing board is rotated to generate the second image, and the operation includes: when the canvas drawing board with the first image needs to be angle corrected, rotating the canvas drawing board with the first image and performing a compression operation.
[0068] Specifically, after the terminal device 100 sets the size of the canvas drawing board, it determines whether the canvas drawing board needs to be corrected in angle. If the angle of the canvas drawing board with the first picture is inconsistent with the angle of the first picture, the terminal device 100 rotates the angle of the canvas drawing board and makes the angle of the canvas drawing board with the first picture consistent with the angle of the first picture. After the terminal device 100 rotates the canvas drawing board to the correct position, it performs a compression processing operation on the canvas panel. Figure 5a What is shown is a schematic diagram of the interface of the first picture set on the canvas panel; Figure 5b FIG. 1 shows an interface diagram of a first image after rotation set on a canvas panel. Figure 5a and Figure 5b As shown, the position information of the canvas drawing board with the first picture generated after the terminal device 100 performs compression processing operation has changed relative to the first picture. Therefore, if the position information of the canvas drawing board with the first picture is to be consistent with the first picture, the terminal device 100 needs to rotate the canvas drawing board with the first picture 90° clockwise, so as to generate a second picture with the same position information as the first picture. Thus, by correcting the rotation angle of the canvas drawing board with the first picture, the technical effect of being able to solve the problem of incompatibility of pictures in some mobile terminals is achieved.
[0069] Optionally, the method further includes: determining whether the output format of the second image is of blob type; and when the output format of the second image is of blob type, determining whether there is a toBlob method in the environment where the second image is located.
[0070] Specifically, the terminal device 100 needs to determine in advance whether the user selects the output format type of the second image according to his or her needs. In the case where the format type of the second image selected by the user is a blob type, the terminal device 100 needs to determine whether there is a toBlob method in the environment where the second image generated by the compression processing operation of the first image is located. In the case where the format type of the second image selected by the user is not a blob type, the terminal device 100 directly outputs the processed second image. Thus, the terminal device 100 determines the output format type of the second image in advance and determines whether there is a toblob method in the environment where the second image is located when the format type selected by the user is a blob type. This can achieve the technical effect that the user does not need to perform format conversion but directly specifies the output format of the second image.
[0071] Preferably, the output format of the second image supports blob format and base64 format.
[0072] Optionally, the operation of determining whether the predetermined output format of the second image is of the blob type includes: outputting the second image if the predetermined output format of the second image is not of the blob type; and determining whether a toBlob method exists in the environment in which the second image is located if the predetermined output format of the second image is of the blob type.
[0073] Specifically, when the format type of the second picture that the user needs to output is not a blob type, the terminal device 100 directly outputs the second picture that has been processed by the compression processing operation. When the format type of the second picture that the user needs to output is a blob type, the terminal device 100 determines whether there is a toBlob method in the environment where the second picture is located. Thus, by pre-determining whether there is a toBlob method in the environment where the second picture is located, the technical effect of being able to pre-determine whether the terminal device 100 can export the blob format is achieved.
[0074] Optionally, when the predetermined output format of the second image is a blob type, the operation of determining whether a toBlob method exists in the environment where the second image is located includes: when the toBlob method does not exist in the environment where the second image is located, customizing the toBlob method and outputting the second image; and when the toBlob method exists in the environment where the second image is located, outputting the second image.
[0075] Specifically, if the terminal device 100 has pre-determined the environment where the second image is located and the environment where the second image is located does not have a toBlob method, the terminal device 100 needs to customize the toBlob method. The toBlob method is customized so that the second image can be successfully output in a blob type format. If the environment where the second image is located has a toBlob method, the terminal device directly outputs the second image.
[0076] Thus, through the technical solution of this embodiment, the user inputs the first picture and the target parameter value on the terminal device 100, and the terminal device 100 determines the first picture and the target parameter value, and performs image processing on the first picture according to the target parameter value, which can achieve the technical effect of simultaneously meeting the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in the mobile terminal are compatible. This solves the technical problem that the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in some mobile terminals are not compatible, which exists in the prior art.
[0077] In addition, reference Figure 1 As shown, according to the second aspect of this embodiment, a storage medium is provided, wherein the storage medium includes a stored program, wherein when the program is run, a processor executes any one of the above methods.
[0078] Thus, through the technical solution of this embodiment, the user inputs the first picture and the target parameter value on the terminal device 100, and the terminal device 100 determines the first picture and the target parameter value, and performs image processing on the first picture according to the target parameter value, which can achieve the technical effect of simultaneously meeting the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in the mobile terminal are compatible. This solves the technical problem that the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in some mobile terminals are not compatible, which exists in the prior art.
[0079] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0080] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0081] Example 2
[0082] Figure 6 The apparatus 600 for compressing a picture according to this embodiment is shown, and the apparatus 600 corresponds to the method according to the first aspect of embodiment 1. Figure 6 As shown, the device 600 includes: a determination module 610, used to determine a first image to be compressed and a target parameter value, wherein the target parameter value is a maximum limit image parameter value of the compressed first image; a processing module 620, used to perform image processing on the first image; and a generation module 630, used to generate a second image corresponding to the target parameter value.
[0083] Optionally, a determination module 610 is used to determine the first image to be compressed and the target parameter value, wherein the target parameter value is the maximum limit image parameter value of the compressed first image, including: a parsing module, used to obtain the original parameter value of the first image, wherein the original parameter value is the image information value of the first image; and a first processing sub-module, used to determine the target parameter value, and perform image processing on the first image according to the target parameter value.
[0084] Optionally, the processing module 620, used to perform image processing on the first image, includes: a comparison module, used to compare the original parameter value with the target parameter value; and a second processing submodule, used to perform image processing on the first image to generate a second image when the original parameter value is different from the target parameter value.
[0085] Optionally, the device 600 further includes: a configuration module, configured to initialize a canvas drawing board according to a target parameter value configuration when the first picture is of an Image type, wherein the first picture is set on the canvas drawing board.
[0086] Optionally, the first processing submodule includes: a first setting module, used to set the maximum storage value, maximum width value, maximum height value and maximum aspect ratio for compressing the first image; and a rotation module, used to rotate the canvas drawing board with the first image when the positions of the first image and the canvas drawing board with the first image are different, so as to generate a second image.
[0087] Optionally, the comparison module includes: a first judgment module, used to judge whether the aspect ratio of the first image is greater than the maximum aspect ratio set by the target parameter value when the width value of the first image is greater than the maximum width value set by the target parameter value and / or the height value of the first image is greater than the maximum height value set by the target parameter value; and a setting module, used to set the canvas drawing board size according to the width value and height value set for the first image when the width value of the first image is less than the maximum width value set by the target parameter value and / or the height value of the first image is less than the maximum height value set by the target parameter value.
[0088] Optionally, the comparison module also includes: a second setting module, which is used to use the maximum width value set by the target parameter value as the width value of the second picture and the product of the maximum width value set by the target parameter value and the aspect ratio of the first picture as the height value of the second picture when the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value; and a third setting module, which is used to use the maximum height value set by the target parameter value as the height value of the second picture and the product of the maximum height value set by the target parameter value and the aspect ratio of the first picture as the width value of the second picture when the aspect ratio of the first picture is less than the maximum aspect ratio set by the target parameter value.
[0089] Optionally, the device 600 further includes: a fourth setting module, configured to set the canvas drawing board size according to the width value and the height value of the pre-generated second image when the width value and the height value of the pre-generated second image are determined.
[0090] Optionally, the configuration module includes: a rotation submodule, which is used to rotate the canvas drawing board with the first picture and perform a compression processing operation when the canvas drawing board with the first picture needs to be angle corrected.
[0091] Optionally, the device 600 also includes: a second judgment module, used to judge whether the predetermined output format of the second image is a blob type; and a third judgment module, used to judge whether there is a toBlob method in the environment where the second image is located when the predetermined output format of the second image is a blob type.
[0092] Optionally, the third judgment module includes: a first output module, used to output the second image when the predetermined output format of the second image is not the blob type; and a second output module, used to determine whether there is a toBlob method in the environment where the second image is located when the predetermined output format of the second image is the blob type.
[0093] Optionally, the second output module includes: a third output module, used to customize the toBlob method and output the second image when the toBlob method does not exist in the environment where the second image is located; and a fourth output module, used to output the second image when the toBlob method exists in the environment where the second image is located.
[0094] Thus, through the technical solution of this embodiment, the user inputs the first picture and the target parameter value on the terminal device 100, and the terminal device 100 determines the first picture and the target parameter value, and performs image processing on the first picture according to the target parameter value, which can achieve the technical effect of simultaneously meeting the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in the mobile terminal are compatible. This solves the technical problem that the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in some mobile terminals are not compatible, which exists in the prior art.
[0095] Example 3
[0096] Figure 7 FIG. 7 shows a picture compression device 700 according to this embodiment, which corresponds to the method according to the first aspect of embodiment 1. Figure 7 As shown, the device 700 includes: a processor 710; and a memory 720, which is connected to the processor 710 and is used to provide instructions for the processor 710 to process the following processing steps: determining a first image to be compressed and a target parameter value, wherein the target parameter value is a maximum limit image parameter value of the compressed first image; performing image processing on the first image; and generating a second image corresponding to the target parameter value.
[0097] Optionally, determining the first image to be compressed and the target parameter value, wherein the target parameter value is the maximum limit image parameter value of the compressed first image, includes: parsing the first image, obtaining the original parameter value of the first image, wherein the original parameter value is the image information value of the first image; and determining the target parameter value, and performing image processing on the first image according to the target parameter value.
[0098] Optionally, the operation of performing image processing on the first picture includes: comparing the original parameter value with the target parameter value; and when the original parameter value is different from the target parameter value, performing image processing on the first picture to generate the second picture.
[0099] Optionally, the method further includes: when the first image is of the Image type, initializing a canvas drawing board according to a target parameter value configuration, wherein the first image is set on the canvas drawing board.
[0100] Optionally, setting a target parameter value and performing image processing on the first picture according to the target parameter value includes: setting a maximum storage value, a maximum width value, a maximum height value and a maximum aspect ratio for compressing the first picture; and when the first picture and the canvas drawing board on which the first picture is set are at different positions, rotating the canvas drawing board on which the first picture is set to generate a second picture.
[0101] Optionally, the operation of comparing the original parameter value with the target parameter value includes: when the width value of the first image is greater than the maximum width value set by the target parameter value and / or the height value of the first image is greater than the maximum height value set by the target parameter value, determining whether the aspect ratio of the first image is greater than the maximum aspect ratio set by the target parameter value; and when the width value of the first image is less than the maximum width value set by the target parameter value and / or the height value of the first image is less than the maximum height value set by the target parameter value, setting the canvas drawing board size according to the width value and height value set for the first image.
[0102] Optionally, the operation of comparing the original parameter value with the target parameter value also includes: when the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value, using the maximum width value set by the target parameter value as the width value of the second picture and using the product of the maximum width value set by the target parameter value and the aspect ratio of the first picture as the height value of the second picture; and when the aspect ratio of the first picture is less than the maximum aspect ratio set by the target parameter value, using the maximum height value set by the target parameter value as the height value of the second picture and using the product of the maximum height value set by the target parameter value and the aspect ratio of the first picture as the width value of the second picture.
[0103] Optionally, the method further includes: when determining the width value and the height value of the pre-generated second image, setting the canvas drawing board size according to the width value and the height value of the pre-generated second image.
[0104] Optionally, when the positions of the first image and the canvas drawing board are different, the canvas drawing board is rotated to generate the second image, and the operation includes: when the canvas drawing board with the first image needs to be angle corrected, rotating the canvas drawing board with the first image and performing a compression operation.
[0105] Optionally, the method further includes: determining whether the predetermined output format of the second image is a blob type; and when the predetermined output format of the second image is a blob type, determining whether a toBlob method exists in the environment where the second image is located.
[0106] Optionally, the operation of determining whether the output format of the second image is of the blob type includes: outputting the second image when the predetermined output format of the second image is not of the blob type; and determining whether a toBlob method exists in the environment in which the second image is located when the predetermined output format of the second image is of the blob type.
[0107] Optionally, when the predetermined output format of the second image is a blob type, the operation of determining whether a toBlob method exists in the environment where the second image is located includes: when the toBlob method does not exist in the environment where the second image is located, customizing the toBlob method and outputting the second image; and when the toBlob method exists in the environment where the second image is located, outputting the second image.
[0108] Thus, through the technical solution of this embodiment, the user inputs the first picture and the target parameter value on the terminal device 100, and the terminal device 100 determines the first picture and the target parameter value, and performs image processing on the first picture according to the target parameter value, which can achieve the technical effect of simultaneously meeting the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in the mobile terminal are compatible. This solves the technical problem that the requirements of compressing pictures according to set parameters, controlling picture size, and ensuring picture clarity, and pictures in some mobile terminals are not compatible, which exists in the prior art.
[0109] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0110] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0111] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0112] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0113] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0114] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0115] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for compressing an image, characterized in that: include: Determine a first picture to be compressed and a target parameter value, wherein the target parameter value is a maximum restricted picture parameter value of the first picture after compression; Performing image compression processing on the first picture; as well as generating a second picture corresponding to the target parameter value; The operation of determining a first picture to be compressed and a target parameter value, wherein the target parameter value is a maximum limit picture parameter value of the compressed first picture, comprises: parsing the first picture to obtain an original parameter value of the first picture, wherein the original parameter value is a picture information value of the first picture; and The operation of determining the target parameter value and performing image processing on the first picture according to the target parameter value includes: Setting a maximum storage value, a maximum width value, a maximum height value, and a maximum aspect ratio for compressing the first picture; and In the case where the first picture and the canvas drawing board on which the first picture is set are located at different positions, rotating the canvas drawing board on which the first picture is set to generate the second picture; The operation of performing the image processing on the first picture includes: comparing the original parameter value with the target parameter value; and In the case where the original parameter value is different from the target parameter value, the first picture is subjected to the image processing to generate the second picture, wherein The operation of comparing the original parameter value with the target parameter value includes: If the width of the first picture is greater than the maximum width set by the target parameter value and / or the height of the first picture is greater than the maximum height set by the target parameter value, determining whether the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value; and When the width value of the first picture is smaller than the maximum width value set by the target parameter value and / or the height value of the first picture is smaller than the maximum height value set by the target parameter value, setting the canvas drawing board size according to the width value and the height value set by the first picture; In a case where the aspect ratio of the first picture is greater than the maximum aspect ratio set by the target parameter value, taking the maximum width value set by the target parameter value as the width value of the second picture and taking the product of the maximum width value set by the target parameter value and the aspect ratio of the first picture as the height value of the second picture; In a case where the aspect ratio of the first picture is smaller than the maximum aspect ratio set by the target parameter value, taking the maximum height value set by the target parameter value as the height value of the second picture and taking the product of the maximum height value set by the target parameter value and the aspect ratio of the first picture as the width value of the second picture; and When the width and height of the pre-generated second image are determined, setting the canvas drawing board size according to the width and height of the pre-generated second image; In the case where the first picture is of the Image type, configuring and initializing a canvas drawing board according to the target parameter value, wherein the first picture is set on the canvas drawing board; When the positions of the first image and the canvas drawing board are different, the operation of rotating the canvas drawing board to generate the second image includes: In the case where the canvas drawing board provided with the first picture needs to be angle corrected, rotating the canvas drawing board provided with the first picture and performing a compression processing operation; Determining whether the predetermined output format of the second image is a blob type; and When the predetermined output format of the second image is a blob type, determining whether a toBlob method exists in the environment where the second image is located; The operation of determining whether the output format of the second image is a blob type includes: If the predetermined output format of the second picture is not a blob type, output the second picture; and When the predetermined output format of the second image is a blob type, the operation of determining whether a toBlob method exists in an environment where the second image is located includes: If the environment where the second image is located does not have a toBlob method, customize the toBlob method and output the second image; and When the environment where the second image is located has a toBlob method, the second image is output.
2. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is executed, the method of claim 1 is executed by a processor.
3. A device for compressing an image, characterized in that: The device for compressing pictures adopts the method according to claim 1, comprising: A determination module, configured to determine a first image to be compressed and a target parameter value, wherein the target parameter value is a maximum limit image parameter value of the first image after compression; a processing module, configured to perform image compression processing on the first picture; and A generating module is used to generate a second picture corresponding to the target parameter value.
4. A device for compressing an image, characterized in that: The device for compressing pictures adopts the method according to claim 1, comprising: Processor; and A memory, connected to the processor, configured to provide the processor with instructions for processing the following processing steps: Determine a first picture to be compressed and a target parameter value, wherein the target parameter value is a maximum restricted picture parameter value of the first picture after compression; performing image compression processing on the first picture; and A second picture corresponding to the target parameter value is generated.
Citation Information
Patent Citations
Picture compression method and apparatus, device and storage medium
CN109640090A