Picture compression method, device and storage medium

文档序号:1906238 发布日期:2021-11-30 浏览:27次 中文

阅读说明:本技术 图片压缩方法、装置以及存储介质 (Picture compression method, device and storage medium ) 是由 李宁 陈凌云 张一鹏 陈映贵 陈炎 于 2021-08-04 设计创作,主要内容包括:本申请公开了一种图片压缩方法、装置以及存储介质。其中,一种图片压缩方法,包括:在所获取的原始图片的存储大小大于预设的第一阈值的情况下,根据预设的质量参数对原始图片进行质量压缩,得到第一图片;在第一图片的存储大小大于预设的第二阈值的情况下,将第一图片作为尺寸压缩对象,并根据预设的图片尺寸大小对尺寸压缩对象进行尺寸压缩,得到第二图片;以及在第二图片的存储大小大于预设的第三阈值的情况下,将第二图片作为质量循环压缩对象,并对质量循环压缩对象进行迭代循环质量压缩,直至压缩得到的目标图片的存储大小不大于预设的目标大小或者目标图片的质量参数等于预设的第一质量参数阈值。(The application discloses a picture compression method, a picture compression device and a storage medium. The picture compression method comprises the following steps: under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture; under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; and under the condition that the storage size of the second picture is larger than a preset third threshold, taking the second picture as a quality cycle compression object, and performing iterative cycle quality compression on the quality cycle compression object until the storage size of the target picture obtained by compression is not larger than the preset target size or the quality parameter of the target picture is equal to the preset first quality parameter threshold.)

1. A picture compression method, comprising:

under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture;

under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; and

under the condition that the storage size of the second picture is larger than a preset third threshold value, taking the second picture as a quality cycle compression object, and performing iterative cycle quality compression on the quality cycle compression object until the storage size of a target picture obtained by compression is not larger than a preset target size or the quality parameter of the target picture is equal to a preset first quality parameter threshold value, wherein the quality parameter of the target picture is equal to a preset first quality parameter threshold value, and in addition, the quality parameter of the target picture is not larger than the preset target size

The first threshold is greater than the second threshold, the second threshold is greater than the third threshold, and the third threshold is greater than the target size; and in the process of performing each round of quality compression on the quality cycle compression object, taking the picture obtained by the previous round of compression as the quality cycle compression object of the current round, determining the decrement of the quality parameter of the current round according to the current storage size and the current residual quality parameter of the picture, and performing the quality compression of the current round on the picture according to the decrement of the quality parameter.

2. The method according to claim 1, wherein the operation of determining the decrement of the quality parameter of the current round according to the current storage size of the picture and the current remaining quality parameter comprises:

judging whether the current remaining quality parameter of the picture is larger than a preset second quality parameter threshold value, wherein the second quality parameter threshold value is larger than the first quality parameter threshold value;

determining the quality parameter decrement of the current turn according to the current storage size of the picture under the condition that the current residual quality parameter of the picture is larger than the preset second quality parameter threshold; and

and under the condition that the current remaining quality parameter of the picture is not larger than the preset second quality parameter threshold value, determining a preset first quality parameter decrement amount as a quality parameter decrement amount of the current turn.

3. The method according to claim 2, wherein the operation of determining the decrement of the quality parameter of the current round according to the current storage size of the picture in the case that the current remaining quality parameter of the picture is greater than the preset second quality parameter threshold value comprises:

determining a preset second quality parameter decrement as a quality parameter decrement of the current round under the condition that the current storage size of the picture is larger than 2 times of the storage size of the target picture;

determining a preset third quality parameter decrement amount as a quality parameter decrement amount of a current round under the condition that the current storage size of the picture is not more than 2 times of the storage size of the target picture and is more than 1.5 times of the storage size of the target picture; and

determining a preset fourth quality parameter decrement amount as a quality parameter decrement amount of the current round in the case that the current storage size of the picture is not more than 1.5 times the storage size of the target picture and is more than the storage size of the target picture, and wherein

The second decreasing amount is greater than the third decreasing amount, the third decreasing amount is greater than the fourth decreasing amount, and the fourth decreasing amount is greater than the first decreasing amount.

4. The method of claim 1, wherein performing a current round of quality compression on the picture according to the quality parameter decrement comprises:

determining a difference value between the current remaining quality parameter of the picture and the quality parameter decrement as a current quality parameter of the current round; and

and performing quality compression of the current round on the picture according to the current quality parameter.

5. The method of claim 1, further comprising:

under the condition that the storage size of the original picture is not larger than the preset first threshold, judging whether the storage size of the original picture is larger than the preset second threshold or not;

taking the original picture as the size compression object under the condition that the storage size of the original picture is judged to be larger than the preset second threshold value; and

and taking the original picture as the quality cycle compression object under the condition that the storage size of the original picture is judged to be not larger than the preset second threshold value.

6. The method of claim 1, further comprising:

and taking the original picture as the quality cycle compression object under the condition that the storage size of the first picture is not larger than the preset second threshold value.

7. The method of claim 1, wherein the operation of performing size compression on the first picture according to a preset picture size to obtain a second picture comprises:

judging whether the side length of the first picture is larger than the preset picture size, wherein the preset picture size is used for indicating a pixel value corresponding to the side length of the picture;

under the condition that the side length of the first picture is judged to be larger than the preset picture size, determining a size compression ratio according to the size of the longest side of the first picture and the preset picture size, and performing size compression on the first picture according to the determined size compression ratio to obtain a second picture; and

and under the condition that the side length of the first picture is not larger than the preset picture size, taking the original picture as the quality cyclic compression object.

8. A storage medium comprising a stored program, wherein the method of any one of claims 1 to 7 is performed by a processor when the program is run.

9. A picture compression apparatus, comprising:

the first compression module is used for performing quality compression on the original picture according to a preset quality parameter under the condition that the storage size of the acquired original picture is larger than a preset first threshold value to obtain a first picture;

the second compression module is used for taking the first picture as a size compression object under the condition that the storage size of the first picture is larger than a preset second threshold value, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; and

a third compression module, configured to, when the storage size of the second picture is larger than a preset third threshold, use the second picture as a quality loop compression object, and perform iterative loop quality compression on the quality loop compression object until the storage size of a target picture obtained by compression is not larger than a preset target size or a quality parameter of the target picture is equal to a preset first quality parameter threshold, where the storage size of the target picture is larger than the preset third threshold, and the target picture is compressed by the iterative loop quality compression module, and the quality parameter of the target picture is equal to the preset first quality parameter threshold

The first threshold is greater than the second threshold, the second threshold is greater than the third threshold, and the third threshold is greater than the target size; and in the process of performing each round of quality compression on the quality cycle compression object, taking the picture obtained by the previous round of compression as the quality cycle compression object of the current round, determining the decrement of the quality parameter of the current round according to the current storage size and the current residual quality parameter of the picture, and performing the quality compression of the current round on the picture according to the decrement of the quality parameter.

10. A picture compression apparatus, comprising:

a processor; and

a memory coupled to the processor for providing instructions to the processor for processing the following processing steps:

under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture;

under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; and

under the condition that the storage size of the second picture is larger than a preset third threshold value, taking the second picture as a quality cycle compression object, and performing iterative cycle quality compression on the quality cycle compression object until the storage size of a target picture obtained by compression is not larger than a preset target size or the quality parameter of the target picture is equal to a preset first quality parameter threshold value, wherein the quality parameter of the target picture is equal to a preset first quality parameter threshold value, and in addition, the quality parameter of the target picture is not larger than the preset target size

The first threshold is greater than the second threshold, the second threshold is greater than the third threshold, and the third threshold is greater than the target size; and in the process of performing each round of quality compression on the quality cycle compression object, taking the picture obtained by the previous round of compression as the quality cycle compression object of the current round, determining the decrement of the quality parameter of the current round according to the current storage size and the current residual quality parameter of the picture, and performing the quality compression of the current round on the picture according to the decrement of the quality parameter.

Technical Field

The present application relates to the field of image processing technologies, and in particular, to an image compression method, an image compression apparatus, and a storage medium.

Background

At present, pictures need to be uploaded in various types of application programs, but the picture quality is different and may not meet the requirements, so that the pictures need to be compressed, but the picture quality may be seriously reduced in the compression process.

For example, when a security account is opened, a user is required to upload an identity card picture, and the system can identify identity card information. After the user uploads the identity card picture, the system has strict requirements on the size of the identity card picture when identifying the identity card information, and the identity card picture shot by the mobile phone far exceeds the requirements, so that the shot identity card picture needs to be compressed. The identity card pictures required by some security companies require the picture size to be within 200K, and the picture quality is high, so that great challenges exist in the prior art.

In view of the above technical problem in the prior art that the quality requirement of the compressed picture cannot be guaranteed when the picture is compressed to a predetermined storage size, no effective solution has been proposed at present.

Disclosure of Invention

Embodiments of the present application provide a method and an apparatus for compressing a picture, and a storage medium, so as to at least solve a technical problem that a quality requirement of a compressed picture cannot be guaranteed when the picture is compressed to a specified storage size in the prior art.

According to an aspect of an embodiment of the present application, there is provided a picture compression method, including: under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture; under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; under the condition that the storage size of the second picture is larger than a preset third threshold, the second picture is used as a quality cyclic compression object, and iterative cyclic quality compression is carried out on the quality cyclic compression object until the storage size of the target picture obtained by compression is not larger than the preset target size or the quality parameter of the target picture is equal to a preset first quality parameter threshold, wherein the first threshold is larger than the second threshold, the second threshold is larger than the third threshold, and the third threshold is larger than the target size; in the process of performing each round of quality compression on the quality cycle compression object, the picture obtained by the previous round of compression is used as the quality cycle compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

According to another aspect of embodiments of the present application, there is also provided a storage medium including a stored program, wherein the method of any one of the above is performed by a processor when the program is run.

According to another aspect of the embodiments of the present application, there is also provided a picture compression apparatus, including: the first compression module is used for performing quality compression on the original picture according to a preset quality parameter under the condition that the storage size of the acquired original picture is larger than a preset first threshold value to obtain a first picture; the second compression module is used for taking the first picture as a size compression object under the condition that the storage size of the first picture is larger than a preset second threshold value, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; the third compression module is used for taking the second picture as a quality cyclic compression object under the condition that the storage size of the second picture is larger than a preset third threshold value, and performing iterative cyclic quality compression on the quality cyclic compression object until the storage size of the target picture obtained by compression is not larger than the preset target size or the quality parameter of the target picture is equal to the preset first quality parameter threshold value, wherein the first threshold value is larger than the second threshold value, the second threshold value is larger than the third threshold value, and the third threshold value is larger than the target size; in the process of performing each round of quality compression on the quality cycle compression object, the picture obtained by the previous round of compression is used as the quality cycle compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

According to another aspect of the embodiments of the present application, there is also provided a picture compression apparatus, including: a processor; and a memory coupled to the processor for providing instructions to the processor for processing the following processing steps: under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture; under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; under the condition that the storage size of the second picture is larger than a preset third threshold, the second picture is used as a quality cyclic compression object, and iterative cyclic quality compression is carried out on the quality cyclic compression object until the storage size of the target picture obtained by compression is not larger than the preset target size or the quality parameter of the target picture is equal to a preset first quality parameter threshold, wherein the first threshold is larger than the second threshold, the second threshold is larger than the third threshold, and the third threshold is larger than the target size; in the process of performing each round of quality compression on the quality cycle compression object, the picture obtained by the previous round of compression is used as the quality cycle compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

In the embodiment of the present application, the picture compression method involves three picture compression modes, namely, single-round quality compression, size compression and iterative loop quality compression, and the three picture compression modes need to be selectively combined according to the storage size of an original picture to be compressed, so as to compress the storage size of the original picture to a specified size. Under the condition that the difference between the storage size of the obtained original picture to be compressed and the specified size is large (namely the storage size of the picture is larger than a preset first threshold), the method and the device adopt a single-round quality compression mode to carry out quality compression on the original picture, so that the difference between the storage size of the original picture and the specified size is greatly reduced. Under the condition that the difference between the storage size of the picture after the single-round quality compression and the specified size is still large (namely, the storage size of the picture is larger than the preset second threshold), the picture needs to be subjected to size compression by adopting a size compression mode, so that the difference between the storage size of the picture and the specified size is in a reasonable range (namely, the storage size of the picture is not larger than the preset second threshold).

Further, under the condition that the difference between the storage size of the obtained original picture and the specified size is not large (that is, the storage size of the picture is larger than the preset second threshold and smaller than or equal to the preset first threshold), the method and the device do not need to perform single-round quality compression on the original picture, but directly perform size compression on the original picture, so that the difference between the storage size of the picture and the specified size is in a reasonable range (that is, the storage size of the picture is not larger than the preset second threshold). For the pictures with the difference between the storage size and the specified size within a reasonable range, the method adopts an iterative loop quality compression mode to continuously perform quality compression on the pictures until the storage size of the pictures is not larger than the specified size. In addition, in the process of performing each round of quality compression on the picture, the picture obtained by the previous round of compression is required to be used as a quality cyclic compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter. In addition, under the condition that the storage size of the obtained original picture or the storage size of the picture subjected to single-round quality compression is not larger than a preset second threshold, the picture is not required to be subjected to size compression, and iterative loop quality compression is directly performed on the picture.

Therefore, according to the mode, the three image compression modes can be selectively combined and used aiming at the original images with different sizes, so that the storage size of the original image is compressed to the specified size, and meanwhile, the quality of the compressed image can be guaranteed to the maximum extent. The technical effects of compressing the picture to the specified storage size and ensuring the quality requirement of the compressed picture are achieved. And the technical problem that the quality requirement of the compressed picture cannot be ensured under the condition that the picture is compressed to the specified storage size in the prior art is solved.

Drawings

The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:

fig. 1 is a hardware block diagram of a computing device for implementing the method according to embodiment 1 of the present application;

fig. 2 is a schematic flowchart of a picture compression method according to the first aspect of embodiment 1 of the present application;

fig. 3 is a schematic overall flow chart of a picture compression method according to the first aspect of embodiment 1 of the present application;

fig. 4 is a schematic diagram of a picture compression apparatus according to embodiment 2 of the present application; and

fig. 5 is a schematic diagram of a picture compression apparatus according to embodiment 3 of the present application.

Detailed Description

In order to make those skilled in the art better understand the technical solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the described embodiments are merely exemplary of some, and not all, of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.

It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.

Example 1

According to the present embodiment, there is provided a method embodiment of picture compression, it should be noted that the steps shown in the flowchart of the figure may be performed in a computer system such as a set of computer executable instructions, and that while a logical order is shown in the flowchart, in some cases the steps shown or described may be performed in an order different than here.

The method embodiments provided by the present embodiment may be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Fig. 1 shows a hardware configuration block diagram of a computing device for implementing a picture compression method. As shown in fig. 1, the computing device may include one or more processors (which may include, but are 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. Besides, the method can also comprise the following steps: 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 source, and/or a camera. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the electronic device. For example, the computing device may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.

It should be noted that the one or more processors and/or other data processing circuitry described above may be referred to generally herein as "data processing circuitry". The data processing circuitry may be embodied in whole or in part in software, hardware, firmware, or any combination thereof. Further, the data processing circuitry may be a single, stand-alone processing module, or incorporated in whole or in part into any of the other elements in the computing device. As referred to in the embodiments of the application, the data processing circuit acts as a processor control (e.g. selection of a variable resistance termination path connected to the interface).

The memory may be configured to store software programs and modules of application software, such as program instructions/data storage devices corresponding to the picture compression method in the embodiments of the present application, and the processor executes various functional applications and data processing by operating the software programs and modules stored in the memory, that is, implements the picture compression method of the application program. The memory may include high speed random access memory, and may also include 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 memory located remotely from the processor, which may be connected to the computing device over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.

The transmission device is used for receiving or transmitting data via a network. Specific examples of such networks may include wireless networks provided by communication providers of the computing devices. In one example, the transmission device includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device may be a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.

The display may be, for example, a touch screen type Liquid Crystal Display (LCD) that may enable a user to interact with a user interface of the computing device.

It should be noted here that in some alternative embodiments, the computing device shown in fig. 1 described above may include hardware elements (including circuitry), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware and software elements. It should be noted that FIG. 1 is only one example of a particular specific example and is intended to illustrate the types of components that may be present in a computing device as described above.

In the above operating environment, according to a first aspect of the present embodiment, a picture compression method is provided. Fig. 2 shows a flow diagram of the method, which, with reference to fig. 2, comprises:

s202: under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture;

s204: under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; and

s206: and under the condition that the storage size of the second picture is larger than a preset third threshold, taking the second picture as a quality cycle compression object, and performing iterative cycle quality compression on the quality cycle compression object until the storage size of the target picture obtained by compression is not larger than the preset target size or the quality parameter of the target picture is equal to the preset first quality parameter threshold.

And wherein the first threshold is greater than the second threshold, the second threshold is greater than the third threshold, the third threshold is greater than the target size; in the process of performing each round of quality compression on the quality cycle compression object, the picture obtained by the previous round of compression is used as the quality cycle compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

Specifically, the computing device obtains an original picture uploaded by a user and detects a storage size of the original picture. And under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, the computing equipment performs quality compression on the original picture according to preset quality parameters to obtain a first picture. The preset first threshold is, for example, 1MB to 3 MB. Preferably, the first threshold is 1 MB. Jpeg may be set as the compression format first when the computing device determines that the storage size of the original picture is larger than the first threshold. Setting the initial quality parameter of the original picture as 100, and setting the preset quality parameter as 80, the computing device performs quality compression on the original picture by using a quality compression mode according to the quality parameter 80, so as to keep 80% of the original quality of the picture, and obtain the first picture. For example, but not limited to, the storage size of the original picture is 11909KB, the preset first threshold is 1MB, the computing device determines that the storage size of the original picture is larger than 1MB, and then compresses the quality of the original picture to 80%, so as to obtain a picture (i.e., the first picture) with a storage size of 3823 KB. It should be understood that, by compressing the picture until the quality parameter is 80 based on the initial quality parameter 100, the obtained picture does not mean that the storage size is reduced by 20%, but by compressing the quality parameter of the picture to 80 based on the quality parameter 100, the operation cannot accurately obtain the storage size through manual calculation. The image compression strength of the images with different storage sizes is different in the quality compression process, and the quality compression strength is larger when the storage size of the images is larger.

Further, after the computing device obtains the first picture, the storage size of the first picture is obtained, the first picture is used as a size compression object under the condition that the storage size of the first picture is larger than a preset second threshold, and the size compression is carried out on the size compression object according to the preset picture size, so that the second picture is obtained. The predetermined second threshold is, for example, 400KB to 600 KB. Preferably, the second threshold may be 400 KB. For example, but not limited to, the storage size of the first picture is 3823KB, the preset second threshold is 400KB, and since the storage size of the first picture is larger than the preset second threshold, the computing device takes the first picture as a size compression object and obtains a pixel value of the first picture (i.e., the size compression object). The preset first picture size is, for example, 400 pixels to 600 pixels. Preferably, the preset picture size is 400 pixels. The computing device performs size compression on the first picture (namely, the size compression object) according to the pixel values of the long side and the wide side of the picture, and takes the compressed picture as the second picture. If one of the long side and the wide side of the first picture exceeds 400 pixels, the longest side of the first picture is set to 400 pixels and the other side is scaled down with the longest side. If none of the edges of the first picture exceed 400 pixels, the first picture is not size compressed. For example, if the long edge of the first picture with the storage size of 3823KB exceeds 400 pixels, the storage size of the size-compressed picture is 608KB, that is, the storage size of the second picture is 608 KB.

Further, the computing device obtains a storage size of the second picture, and takes the second picture as a quality cycle compression object when the storage size of the second picture is larger than a preset third threshold. The preset third threshold is larger than the target size, for example, in the case of a target size of 200KB, the third threshold is 200KB to 300 KB. Preferably, the third threshold is 200 KB. For example, but not limited to, the storage size of the second picture is 608KB, the preset third threshold is 200KB, and the computing device determines that the storage size of the second picture is larger than the preset third threshold, and then sets the second picture as the quality loop compression object. And then, the computing equipment performs iterative loop quality compression on the quality loop compression object until the storage size of the compressed target picture is not larger than the preset target size or the quality parameter of the target picture is equal to the preset first quality parameter threshold. For example, but not limited to, the storage size of the target picture is 200KB, and the preset first quality parameter threshold is, for example, 1 to 3 KB. Preferably, the first quality parameter is 1. With the initial quality parameter 100 of the quality cycle compression object as a reference, after the computing device performs iterative cycle quality compression on the second picture (i.e. the quality cycle compression object) to the first quality parameter, the compression is stopped no matter whether the storage size of the picture is not larger than a preset target size.

The computing equipment takes the picture obtained by the previous round of compression as the quality cycle compression object of the current round in the process of performing each round of quality compression on the quality cycle compression object, determines the decrement of the quality parameter of the current round according to the current storage size and the current residual quality parameter of the picture, and performs the quality compression of the current round on the picture according to the decrement of the quality parameter. For example, the storage size of the second picture is 608KB, with the initial quality parameter set to 100, and the computing device starts the quality loop of the first round, taking the second picture as the compression target of the quality loop of the current round. Since the current stored size of the second picture is 608KB, the current remaining quality parameter is 100, and both the current stored size of the picture and the current remaining quality parameter are larger, the computing device may determine a larger decrement in the quality parameter (e.g., 15) as the decrement in the quality parameter for the current round. That is, the computing device performs quality compression on the second picture until its quality parameter is 85 (i.e., current remaining quality parameter 100 — quality parameter decrement 15) with reference to current remaining quality parameter 100. And then starting the second round of quality compression, and taking the picture obtained by the first round of compression as a quality cyclic compression object of the second round. The computing device obtains the current memory size and the current remaining quality parameter (i.e., 85) of the quality loop compression object for the second round and re-determines the amount of quality parameter decrement (e.g., 2) for the current round. The computing device then compresses the object of the quality loop compression until the quality parameter is 83, with the current remaining quality parameter 85 as a reference, resulting in a target picture of 191KB in memory size, and then stops the compression.

As described in the background, currently, pictures need to be uploaded in various types of applications, but the picture quality is different and may not meet the requirement, so that the pictures need to be compressed, but the picture quality may be seriously reduced in the compression process. For example, when a security account is opened, a user is required to upload an identity card picture, and the system can identify identity card information. After the user uploads the identity card picture, the system has strict requirements on the size of the identity card picture when identifying the identity card information, and the identity card picture shot by the mobile phone far exceeds the requirements, so that the shot identity card picture needs to be compressed. The identity card pictures required by some security companies require the picture size to be within 200K, and the picture quality is high, so that great challenges exist in the prior art.

For the above technical problem, according to the technical solution of the embodiment of the present application, the picture compression method involves three picture compression modes, namely, single-round quality compression, size compression and iterative loop quality compression, and the three picture compression modes need to be selectively combined according to the storage size of the original picture to be compressed, so as to compress the storage size of the original picture to a specified size. Under the condition that the difference between the storage size of the obtained original picture to be compressed and the specified size is large (namely the storage size of the picture is larger than a preset first threshold), the method and the device adopt a single-round quality compression mode to carry out quality compression on the original picture, so that the difference between the storage size of the original picture and the specified size is greatly reduced. Under the condition that the difference between the storage size of the picture after the single-round quality compression and the specified size is still large (namely, the storage size of the picture is larger than the preset second threshold), the picture needs to be subjected to size compression by adopting a size compression mode, so that the difference between the storage size of the picture and the specified size is in a reasonable range (namely, the storage size of the picture is not larger than the preset second threshold).

Further, for the pictures with the difference between the storage size and the specified size within a reasonable range, the method adopts an iterative loop quality compression mode to continuously perform quality compression on the pictures until the storage size of the pictures is not larger than the specified size. In addition, in the process of performing each round of quality compression on the picture, the picture obtained by the previous round of compression is required to be used as a quality cyclic compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

Therefore, by the mode, the storage size of the original picture is compressed to the specified size, and meanwhile, the quality of the compressed picture can be guaranteed to the maximum extent. The technical effects of compressing the picture to the specified storage size and ensuring the quality requirement of the compressed picture are achieved. And the technical problem that the quality requirement of the compressed picture cannot be ensured under the condition that the picture is compressed to the specified storage size in the prior art is solved.

Optionally, the operation of determining the quality parameter decrement of the current round according to the current storage size of the picture and the current remaining quality parameter includes: judging whether the current remaining quality parameter of the picture is larger than a preset second quality parameter threshold value, wherein the second quality parameter threshold value is larger than the first quality parameter threshold value; determining the quality parameter decrement of the current round according to the current storage size of the picture under the condition that the current residual quality parameter of the picture is larger than a preset second quality parameter threshold; and under the condition that the current remaining quality parameter of the picture is not larger than a preset second quality parameter threshold value, determining a preset first quality parameter decrement amount as a quality parameter decrement amount of the current turn.

Specifically, referring to fig. 3, in the process of performing iterative loop quality compression on the quality loop compression object, for the operation of determining the quality parameter decrement of the current round, the computing device may first determine whether the current remaining quality parameter of the picture is greater than a preset second quality parameter threshold. The second quality parameter threshold is greater than the first quality parameter threshold, and the preset second quality parameter threshold is, for example, 15. And under the condition that the current residual quality parameter of the picture is larger than a preset second quality parameter threshold value, determining the quality parameter decrement of the current round according to the current storage size of the picture. For example, the computing device sets the initial quality parameter to 100, and then the current remaining quality parameter of the picture is 100, and then the computing device determines that the current remaining quality parameter of the picture is greater than 15. The current storage size of the picture is, for example, 608KB, after which the computing device determines the amount by which the quality parameter of the current round is decremented. And under the condition that the current remaining quality parameter of the picture is not larger than a preset second quality parameter threshold value, determining the preset first quality parameter decrement as the quality parameter decrement of the current turn. For example, the current remaining quality parameter is 14, the second quality parameter threshold is 15, the computing device determines that the current remaining quality parameter is not greater than the second quality parameter threshold 15, and the first quality parameter decrement amount is, for example, 1, so that the quality parameter decrement amount for the current round is 1.

Therefore, in the process of performing the quality compression cycle on the picture, as for the mode of determining the quality parameter decrement of the current round, when performing the quality compression of each round, the computing device firstly determines whether the current remaining quality parameter of the picture is greater than the second quality parameter threshold, and then determines the quality parameter decrement of the current round according to the determination result. After a number of experiments, the second quality parameter threshold was determined to be 15. Because the inventor finds that when the second quality parameter threshold is 15, the applicability to picture compression is strongest, and pictures with different sizes can be adapted, so that the pictures can be effectively compressed. And the subsequent compression times are more reasonable, and a reasonable standard is provided for the subsequent determination of the quality parameter decrement.

Optionally, when the current remaining quality parameter of the picture is greater than a preset second quality parameter threshold, the operation of determining the quality parameter decrement of the current round according to the current storage size of the picture includes:

s302: and under the condition that the current storage size of the picture is larger than 2 times of the storage size of the target picture, determining the preset second quality parameter decrement as the quality parameter decrement of the current round.

Specifically, referring to fig. 3, after determining that the current remaining quality parameter is greater than the preset second quality parameter threshold 15, the computing device acquires the current storage size of the picture, and determines the preset second quality parameter decrement amount as the quality parameter decrement amount of the current round if the current storage size is greater than 2 times of the storage size of the target picture. For example, if the current storage size of the picture is 500KB and the storage size of the target picture is 200KB, then the current storage size of 500KB is greater than 2 times the storage size of 200KB of the target picture, and the second quality parameter decrement amount is, for example, 15, then the computing device may determine the second quality parameter decrement amount of 15 as the quality parameter decrement amount of the current round. And then the computing equipment performs quality compression processing on the picture according to the quality parameter decrement.

S304: and under the condition that the current storage size of the picture is not more than 2 times of the storage size of the target picture and is more than 1.5 times of the storage size of the target picture, determining the preset third quality parameter decrement as the quality parameter decrement of the current round.

Specifically, after the picture passes through step S302, the computing device determines that the current remaining quality parameter is greater than the preset second quality parameter threshold 15, and then obtains the current storage size of the picture. Wherein the second mass parameter decrement is larger than the third mass parameter decrement. For example, the current storage size of the picture is 350KB, the storage size of the target picture is 200KB, the storage size of the picture is not greater than 2 times and greater than 1.5 times the storage size of the target picture, the third quality parameter decrement amount is, for example, 5, and the computing device determines the preset third quality parameter decrement amount of 5 as the quality parameter decrement amount of the current round. And then the computing equipment performs quality compression processing on the picture according to the quality parameter decrement.

S306: and under the condition that the current storage size of the picture is not more than 1.5 times of the storage size of the target picture and is more than the storage size of the target picture, determining a preset fourth quality parameter decrement as the quality parameter decrement of the current turn, wherein the second quality parameter decrement is more than a third quality parameter decrement, the third quality parameter decrement is more than a fourth quality parameter decrement, and the fourth quality parameter decrement is more than the first quality parameter decrement.

Specifically, referring to fig. 3, after the picture passes through step S302 and step S304, the computing device determines that the current remaining quality parameter is greater than the preset second quality parameter threshold 15, and then obtains the current storage size of the picture. Wherein the third decreasing amount of the quality parameter is larger than the fourth decreasing amount of the quality parameter, and the fourth decreasing amount of the quality parameter is larger than the first decreasing amount of the quality parameter. For example, the current storage size of the picture is 260KB, the storage size of the target picture is 200KB, the storage size of the picture is not greater than 1.5 times and greater than 200KB of the storage size of the target picture, the third quality parameter decrement amount is, for example, 2, and the computing device determines the preset third quality parameter decrement amount 2 as the quality parameter decrement amount of the current round. And then the computing equipment performs quality compression processing on the picture according to the quality parameter decrement.

Further, after the picture is subjected to the multiple rounds of iterative loop quality compression of step S302, step S304 and step S306, when the storage size of the picture is less than or equal to 200KB or the remaining quality parameter is equal to 1, the compression is stopped and the picture compression is completed. And then the computing equipment stores the compressed picture to a memory card, reads the picture from the memory card and uploads and identifies the picture.

Therefore, in the process of determining the quality parameter decrement of the current round, the computing device can clearly preset the quality parameter decrement no matter which stage the current storage size of the picture is in under the condition that the current residual quality parameter of the picture is larger than the preset second quality parameter threshold value. After a large number of experiments, the quality parameter decrement is preset to be 15, 5, 2 and 1, and the reasonable quality parameter decrement can be selected by the computing equipment no matter what the storage size of the picture is in the iterative loop quality compression process in such a way, so that the picture is optimally compressed in the iterative loop quality, and the quality of the compressed picture can be ensured to the maximum extent while the storage size of the original picture is compressed to the target size.

Optionally, the performing, according to the quality parameter decrement, a current round of quality compression on the picture includes: determining the difference between the current residual quality parameter of the picture and the quality parameter decrement as the current quality parameter of the current turn; and performing quality compression of the current round on the picture according to the current quality parameters.

Specifically, referring to fig. 3, when performing the quality compression of the current round on the picture according to the quality parameter decrement amount, the computing device determines the difference between the current remaining quality parameter of the picture and the quality parameter decrement amount as the current quality parameter of the current round. For example, if the current remaining quality parameter of the picture is 100, the decrement of the quality parameter is 15, and the current quality parameter is the difference 85 between the current remaining quality parameter and the decrement of the quality parameter. When the quality parameter decrement is 5, 2 and 1, the current quality parameter calculation mode is the same.

Therefore, according to the technical scheme, after each round of picture iterative cycle quality compression, the current quality parameter needs to be recalculated, the difference value between the current residual quality parameter and the quality parameter decrement of the picture is determined as the current quality parameter of the current round, and then the iterative cycle quality compression is performed. Therefore, iterative loop quality compression can be accurately carried out on the picture through the current quality parameters obtained through calculation.

Optionally, the method further comprises: under the condition that the storage size of the original picture is not larger than a preset first threshold, judging whether the storage size of the original picture is larger than a preset second threshold or not; under the condition that the storage size of the original picture is judged to be larger than a preset second threshold value, taking the original picture as a size compression object; and under the condition that the storage size of the original picture is judged to be not larger than a preset second threshold value, taking the original picture as a quality cycle compression object.

Specifically, referring to fig. 3, after acquiring the storage size of the original picture, the computing device determines whether the storage size of the picture is larger than a preset first threshold value 1MB, and if the storage size of the original picture is not larger than the preset first threshold value, determines whether the storage size of the original picture is larger than a preset second threshold value 400 KB. For example, if the storage size of the original picture is 700KB, the storage size of the picture is not larger than the first threshold of 1MB and is larger than the preset second threshold of 400KB, and the computing device performs size compression on the original picture by using the original picture as a size compression target. If the storage size of the original picture is 300KB, the computing device determines that the storage size of the original picture is not larger than a first threshold value of 1MB and not larger than a preset second threshold value of 400KB, and performs iterative loop quality compression on the original picture by taking the original picture as a quality loop compression object.

Therefore, before performing size compression on the original picture, the computing device needs to judge whether the storage size of the picture is larger than a preset first threshold and a preset second threshold, when the storage size of the original picture is not larger than the first threshold, the computing device does not need to perform quality compression on the original picture, and then judges whether the original picture needs to be subjected to size compression according to the second threshold. Therefore, according to the storage size of the original picture, a reasonable compression mode and steps are provided for the original picture by utilizing a preset threshold value.

Optionally, the method further comprises: and under the condition that the storage size of the first picture is judged to be not larger than a preset second threshold value, taking the original picture as a quality cycle compression object.

Specifically, for example, if the storage size of the original picture is 2151KB and is greater than the first threshold 1MB, the computing device performs quality compression on the original picture to obtain a first picture, the storage size of the first picture is 255KB, and then the computing device determines whether the storage size of the first picture is greater than a preset second threshold 400 KB.

Therefore, the strength of quality compression is high, the storage size of a small original picture after quality compression is small, and the small original picture is not suitable for size compression again, so that when the small picture is compressed, the quality compression can be avoided, but the small picture is directly compressed through the size, and then quality cyclic compression is carried out, so that the mode is more reasonable and the friendliness is stronger for the small picture, the technical scheme can be suitable for pictures with different sizes, and when the storage size of the picture is compressed to the specified size, the quality of the picture obtained by compression can be guaranteed to the maximum extent.

In addition, when the storage size of the picture is between 1MB and 3MB, and the storage size of the picture is smaller than the second threshold 400KB after the picture is subjected to quality compression, the picture should be subjected to iterative loop quality compression at this time, but considering that the number of loop turns is greatly increased if the picture is subjected to iterative loop quality compression, the picture may be subjected to size compression and then subjected to iterative loop quality compression. Therefore, in the process of compressing the picture, the compression step of the picture is changed according to the actual situation and the storage size of the picture, and the picture storage size suitable for iterative loop quality compression is obtained, so that the loop times are reduced, the picture compression rate is improved, and the technical scheme is more suitable for pictures with different sizes.

Optionally, the operation of performing size compression on the first picture according to a preset picture size to obtain a second picture includes: judging whether the side length of the first picture is larger than a preset picture size, wherein the preset picture size is used for indicating a pixel value corresponding to the side length of the picture; under the condition that the side length of the first picture is judged to be larger than the preset picture size, determining a size compression ratio according to the size of the longest side of the first picture and the preset picture size, and performing size compression on the first picture according to the determined size compression ratio to obtain a second picture; and under the condition that the side length of the first picture is not larger than the preset picture size, taking the original picture as a quality cycle compression object.

Specifically, referring to fig. 3, before performing size compression on the first picture, the computing device may determine whether a side length of the first picture is greater than a preset picture size. The preset size of the picture size is used for indicating a pixel value corresponding to the side length of the picture, and the preset side length of the picture is, for example, 400 pixels to 600 pixels. Preferably, the picture side is 400 pixels long. The computing device may determine whether the side length of the first picture is greater than a preset side length of the picture, where the preset side length of the picture is, for example, 400 pixels, that is, whether any one of the long side and the short side exceeds 400 pixels. And then under the condition that the side length of the first picture is judged to be larger than the preset picture size by the computing equipment, determining a size compression ratio according to the length of the longest side of the first picture and the preset picture size, and performing size compression on the first picture according to the determined size compression ratio to obtain a second picture. For example, if the length of the first picture is 700 pixels and the width of the first picture is 300 pixels, the side length of the first picture is larger than the preset picture size, the computing device will compress the first picture to have a longest side equal to 400 pixels according to the size of the longest side of the first picture (i.e. 700 pixels), and the short side of the first picture is also reduced with equal scale. Therefore, in the case of a length of 700 pixels and a width of 300 pixels, the size compression ratio is 7: and 3, the side length of a second picture obtained by performing size compression on the first picture by the computing equipment according to the size compression ratio is not more than 400 pixels. In addition, when the computing equipment judges that the side length of the first picture is not larger than the preset picture size, the original picture is used as a quality cycle compression object, iteration cycle quality compression is directly carried out on the original picture, and quality compression is not carried out on the original picture any more.

Therefore, when the computing device performs size compression on the first picture, whether the size compression is required or not needs to be determined according to the side length of the picture. And under the condition that the side length of the first picture is judged to be larger than the preset picture size, the computing equipment performs size compression on the first picture. In addition, under the condition that the side length of the first picture is not larger than the preset picture size, the computing device takes the original picture as a quality cycle compression object. Therefore, in the technical scheme, under the condition that the storage size of the picture is larger than 400KB but the side length is shorter, if the picture after quality compression is subjected to iterative loop quality compression, the picture is blurred, and the definition is too low. Therefore, according to the actual situation, the original picture is directly subjected to iterative loop quality compression, and the original picture is not subjected to quality compression any more, so that the quality of the compressed picture can be ensured to the maximum extent while the storage size of the picture is compressed to the specified size.

Further, referring to fig. 1, according to a second aspect of the present embodiment, there is provided a storage medium. The storage medium comprises a stored program, wherein the method of any of the above is performed by a processor when the program is run.

Therefore, according to the present embodiment, the picture compression method involves three picture compression modes, namely, single-pass quality compression, size compression and iterative loop quality compression, and the three picture compression modes need to be selectively combined according to the storage size of the original picture to be compressed, so as to compress the storage size of the original picture to a specified size. Under the condition that the difference between the storage size of the obtained original picture to be compressed and the specified size is large (namely the storage size of the picture is larger than a preset first threshold), the method and the device adopt a single-round quality compression mode to carry out quality compression on the original picture, so that the difference between the storage size of the original picture and the specified size is greatly reduced. Under the condition that the difference between the storage size of the picture after the single-round quality compression and the specified size is still large (namely, the storage size of the picture is larger than the preset second threshold), the picture needs to be subjected to size compression by adopting a size compression mode, so that the difference between the storage size of the picture and the specified size is in a reasonable range (namely, the storage size of the picture is not larger than the preset second threshold).

Further, under the condition that the difference between the storage size of the obtained original picture and the specified size is not large (that is, the storage size of the picture is larger than the preset second threshold and smaller than or equal to the preset first threshold), the method and the device do not need to perform single-round quality compression on the original picture, but directly perform size compression on the original picture, so that the difference between the storage size of the picture and the specified size is in a reasonable range (that is, the storage size of the picture is not larger than the preset second threshold). For the pictures with the difference between the storage size and the specified size within a reasonable range, the method adopts an iterative loop quality compression mode to continuously perform quality compression on the pictures until the storage size of the pictures is not larger than the specified size. In addition, in the process of performing each round of quality compression on the picture, the picture obtained by the previous round of compression is required to be used as a quality cyclic compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter. In addition, under the condition that the storage size of the obtained original picture or the storage size of the picture subjected to single-round quality compression is not larger than a preset second threshold, the picture is not required to be subjected to size compression, and iterative loop quality compression is directly performed on the picture.

Therefore, according to the mode, the three image compression modes can be selectively combined and used aiming at the original images with different sizes, so that the storage size of the original image is compressed to the specified size, and meanwhile, the quality of the compressed image can be guaranteed to the maximum extent. The technical effects of compressing the picture to the specified storage size and ensuring the quality requirement of the compressed picture are achieved. And the technical problem that the quality requirement of the compressed picture cannot be ensured under the condition that the picture is compressed to the specified storage size in the prior art is solved.

It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.

Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.

Example 2

Fig. 4 shows a picture compression apparatus 400 according to the present embodiment, the apparatus 400 corresponding to the method according to the first aspect of embodiment 1. Referring to fig. 4, the apparatus 400 includes: a first compression module 410, configured to, when a storage size of the obtained original picture is greater than a preset first threshold, perform quality compression on the original picture according to a preset quality parameter to obtain a first picture; the second compression module 420 is configured to, when the storage size of the first picture is larger than a preset second threshold, use the first picture as a size compression object, and perform size compression on the size compression object according to a preset picture size to obtain a second picture; and a third compression module 430, configured to, when the storage size of the second picture is greater than a preset third threshold, use the second picture as a quality loop compression object, and perform iterative loop quality compression on the quality loop compression object until the storage size of the compressed target picture is not greater than the preset target size or a quality parameter of the target picture is equal to a preset first quality parameter threshold, where the first threshold is greater than the second threshold, the second threshold is greater than the third threshold, and the third threshold is greater than the target size; in the process of performing each round of quality compression on the quality cycle compression object, the picture obtained by the previous round of compression is used as the quality cycle compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

Optionally, the third compression module 430 comprises: the first judgment submodule is used for judging whether the current residual quality parameter of the picture is larger than a preset second quality parameter threshold value, wherein the second quality parameter threshold value is larger than the first quality parameter threshold value; the first determining submodule is used for determining the quality parameter decreasing amount of the current round according to the current storage size of the picture under the condition that the current residual quality parameter of the picture is larger than a preset second quality parameter threshold; and the second determining submodule is used for determining the preset first quality parameter decrement as the quality parameter decrement of the current round under the condition that the current remaining quality parameter of the picture is not larger than the preset second quality parameter threshold.

Optionally, the first determining sub-module includes: a first determining unit, configured to determine a preset second quality parameter decrement amount as a quality parameter decrement amount of a current round when a current storage size of the picture is greater than 2 times a storage size of the target picture; a second determining unit, configured to determine a preset third quality parameter decrement amount as a quality parameter decrement amount of the current round when a current storage size of the picture is not greater than 2 times of a storage size of the target picture and is greater than 1.5 times of the storage size of the target picture; and a third determining unit configured to determine a preset fourth quality parameter decrement amount as a quality parameter decrement amount of the current round if the current storage size of the picture is not greater than 1.5 times the storage size of the target picture and is greater than the storage size of the target picture, and wherein the second quality parameter decrement amount is greater than the third quality parameter decrement amount, the third quality parameter decrement amount is greater than the fourth quality parameter decrement amount, and the fourth quality parameter decrement amount is greater than the first quality parameter decrement amount.

Optionally, the third compression module 430 comprises: a third determining submodule, configured to determine a difference between a current remaining quality parameter of the picture and the quality parameter decrement as a current quality parameter of the current round; and the quality compression submodule is used for performing quality compression of the current round on the picture according to the current quality parameters.

Optionally, the apparatus 400 further comprises: the first judging module is used for judging whether the storage size of the original picture is larger than a preset second threshold value or not under the condition that the storage size of the original picture is not larger than the preset first threshold value; the size compression module is used for taking the original picture as a size compression object under the condition that the storage size of the original picture is judged to be larger than a preset second threshold value; and the first quality compression module is used for taking the original picture as a quality cyclic compression object under the condition that the storage size of the original picture is judged to be not larger than a preset second threshold value.

Optionally, the apparatus 400 further comprises: and the second quality compression module is used for taking the original picture as a quality cyclic compression object under the condition that the storage size of the first picture is judged to be not larger than a preset second threshold value.

Optionally, the second compression module 420 comprises: the second judging submodule is used for judging whether the side length of the first picture is larger than a preset picture size, wherein the preset picture size is used for indicating a pixel value corresponding to the side length of the picture; the size compression sub-module is used for determining a size compression ratio according to the size of the longest edge of the first picture and the size of a preset picture under the condition that the side length of the first picture is judged to be larger than the size of the preset picture, and performing size compression on the first picture according to the determined size compression ratio to obtain a second picture; and the quality compression submodule is used for taking the original picture as a quality cyclic compression object under the condition that the side length of the first picture is not larger than the preset picture size.

Therefore, according to the present embodiment, the picture compression method involves three picture compression modes, namely, single-pass quality compression, size compression and iterative loop quality compression, and the three picture compression modes need to be selectively combined according to the storage size of the original picture to be compressed, so as to compress the storage size of the original picture to a specified size. Under the condition that the difference between the storage size of the obtained original picture to be compressed and the specified size is large (namely the storage size of the picture is larger than a preset first threshold), the method and the device adopt a single-round quality compression mode to carry out quality compression on the original picture, so that the difference between the storage size of the original picture and the specified size is greatly reduced. Under the condition that the difference between the storage size of the picture after the single-round quality compression and the specified size is still large (namely, the storage size of the picture is larger than the preset second threshold), the picture needs to be subjected to size compression by adopting a size compression mode, so that the difference between the storage size of the picture and the specified size is in a reasonable range (namely, the storage size of the picture is not larger than the preset second threshold).

Further, under the condition that the difference between the storage size of the obtained original picture and the specified size is not large (that is, the storage size of the picture is larger than the preset second threshold and smaller than or equal to the preset first threshold), the method and the device do not need to perform single-round quality compression on the original picture, but directly perform size compression on the original picture, so that the difference between the storage size of the picture and the specified size is in a reasonable range (that is, the storage size of the picture is not larger than the preset second threshold). For the pictures with the difference between the storage size and the specified size within a reasonable range, the method adopts an iterative loop quality compression mode to continuously perform quality compression on the pictures until the storage size of the pictures is not larger than the specified size. In addition, in the process of performing each round of quality compression on the picture, the picture obtained by the previous round of compression is required to be used as a quality cyclic compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter. In addition, under the condition that the storage size of the obtained original picture or the storage size of the picture subjected to single-round quality compression is not larger than a preset second threshold, the picture is not required to be subjected to size compression, and iterative loop quality compression is directly performed on the picture.

Therefore, according to the mode, the three image compression modes can be selectively combined and used aiming at the original images with different sizes, so that the storage size of the original image is compressed to the specified size, and meanwhile, the quality of the compressed image can be guaranteed to the maximum extent. The technical effects of compressing the picture to the specified storage size and ensuring the quality requirement of the compressed picture are achieved. And the technical problem that the quality requirement of the compressed picture cannot be ensured under the condition that the picture is compressed to the specified storage size in the prior art is solved.

Example 3

Fig. 5 shows a picture compression apparatus 500 according to the present embodiment, the apparatus 500 corresponding to the method according to the first aspect of embodiment 1. Referring to fig. 5, the apparatus 500 includes: a processor 510; and a memory 520 coupled to processor 510 for providing processor 510 with instructions to process the following process steps: under the condition that the storage size of the obtained original picture is larger than a preset first threshold value, performing quality compression on the original picture according to preset quality parameters to obtain a first picture; under the condition that the storage size of the first picture is larger than a preset second threshold value, taking the first picture as a size compression object, and performing size compression on the size compression object according to the preset picture size to obtain a second picture; under the condition that the storage size of the second picture is larger than a preset third threshold, the second picture is used as a quality cyclic compression object, and iterative cyclic quality compression is carried out on the quality cyclic compression object until the storage size of the target picture obtained by compression is not larger than the preset target size or the quality parameter of the target picture is equal to a preset first quality parameter threshold, wherein the first threshold is larger than the second threshold, the second threshold is larger than the third threshold, and the third threshold is larger than the target size; in the process of performing each round of quality compression on the quality cycle compression object, the picture obtained by the previous round of compression is used as the quality cycle compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter.

Optionally, the operation of determining the quality parameter decrement of the current round according to the current storage size of the picture and the current remaining quality parameter includes: judging whether the current remaining quality parameter of the picture is larger than a preset second quality parameter threshold value, wherein the second quality parameter threshold value is larger than the first quality parameter threshold value; determining the quality parameter decrement of the current round according to the current storage size of the picture under the condition that the current residual quality parameter of the picture is larger than a preset second quality parameter threshold; and under the condition that the current remaining quality parameter of the picture is not larger than a preset second quality parameter threshold value, determining a preset first quality parameter decrement amount as a quality parameter decrement amount of the current turn.

Optionally, when the current remaining quality parameter of the picture is greater than a preset second quality parameter threshold, the operation of determining the quality parameter decrement of the current round according to the current storage size of the picture includes: under the condition that the current storage size of the picture is 2 times larger than that of the target picture, determining the preset second quality parameter decrement amount as the quality parameter decrement amount of the current round; determining a preset third quality parameter decrement amount as a quality parameter decrement amount of the current round under the condition that the current storage size of the picture is not more than 2 times of the storage size of the target picture and is more than 1.5 times of the storage size of the target picture; and under the condition that the current storage size of the picture is not more than 1.5 times of the storage size of the target picture and is more than the storage size of the target picture, determining a preset fourth quality parameter decrement as the quality parameter decrement of the current turn, wherein the second quality parameter decrement is more than the third quality parameter decrement, the third quality parameter decrement is more than the fourth quality parameter decrement, and the fourth quality parameter decrement is more than the first quality parameter decrement.

Optionally, the performing, according to the quality parameter decrement, a current round of quality compression on the picture includes: determining the difference between the current residual quality parameter of the picture and the quality parameter decrement as the current quality parameter of the current turn; and performing quality compression of the current round on the picture according to the current quality parameters.

Optionally, the memory 520 is further configured to provide the processor 510 with instructions to process the following process steps: under the condition that the storage size of the original picture is not larger than a preset first threshold, judging whether the storage size of the original picture is larger than a preset second threshold or not; under the condition that the storage size of the original picture is judged to be larger than a preset second threshold value, taking the original picture as a size compression object; and under the condition that the storage size of the original picture is judged to be not larger than a preset second threshold value, taking the original picture as a quality cycle compression object.

Optionally, the memory 520 is further configured to provide the processor 510 with instructions to process the following process steps: and under the condition that the storage size of the first picture is judged to be not larger than a preset second threshold value, taking the original picture as a quality cycle compression object.

Optionally, the operation of performing size compression on the first picture according to a preset picture size to obtain a second picture includes: judging whether the side length of the first picture is larger than a preset picture size, wherein the preset picture size is used for indicating a pixel value corresponding to the side length of the picture; under the condition that the side length of the first picture is judged to be larger than the preset picture size, determining a size compression ratio according to the size of the longest side of the first picture and the preset picture size, and performing size compression on the first picture according to the determined size compression ratio to obtain a second picture; and under the condition that the side length of the first picture is not larger than the preset picture size, taking the original picture as a quality cycle compression object.

Therefore, according to the present embodiment, the picture compression method involves three picture compression modes, namely, single-pass quality compression, size compression and iterative loop quality compression, and the three picture compression modes need to be selectively combined according to the storage size of the original picture to be compressed, so as to compress the storage size of the original picture to a specified size. Under the condition that the difference between the storage size of the obtained original picture to be compressed and the specified size is large (namely the storage size of the picture is larger than a preset first threshold), the method and the device adopt a single-round quality compression mode to carry out quality compression on the original picture, so that the difference between the storage size of the original picture and the specified size is greatly reduced. Under the condition that the difference between the storage size of the picture after the single-round quality compression and the specified size is still large (namely, the storage size of the picture is larger than the preset second threshold), the picture needs to be subjected to size compression by adopting a size compression mode, so that the difference between the storage size of the picture and the specified size is in a reasonable range (namely, the storage size of the picture is not larger than the preset second threshold).

Further, under the condition that the difference between the storage size of the obtained original picture and the specified size is not large (that is, the storage size of the picture is larger than the preset second threshold and smaller than or equal to the preset first threshold), the method and the device do not need to perform single-round quality compression on the original picture, but directly perform size compression on the original picture, so that the difference between the storage size of the picture and the specified size is in a reasonable range (that is, the storage size of the picture is not larger than the preset second threshold). For the pictures with the difference between the storage size and the specified size within a reasonable range, the method adopts an iterative loop quality compression mode to continuously perform quality compression on the pictures until the storage size of the pictures is not larger than the specified size. In addition, in the process of performing each round of quality compression on the picture, the picture obtained by the previous round of compression is required to be used as a quality cyclic compression object of the current round, the decrement of the quality parameter of the current round is determined according to the current storage size of the picture and the current residual quality parameter, and the quality compression of the current round is performed on the picture according to the decrement of the quality parameter. In addition, under the condition that the storage size of the obtained original picture or the storage size of the picture subjected to single-round quality compression is not larger than a preset second threshold, the picture is not required to be subjected to size compression, and iterative loop quality compression is directly performed on the picture.

Therefore, according to the mode, the three image compression modes can be selectively combined and used aiming at the original images with different sizes, so that the storage size of the original image is compressed to the specified size, and meanwhile, the quality of the compressed image can be guaranteed to the maximum extent. The technical effects of compressing the picture to the specified storage size and ensuring the quality requirement of the compressed picture are achieved. And the technical problem that the quality requirement of the compressed picture cannot be ensured under the condition that the picture is compressed to the specified storage size in the prior art is solved.

The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.

In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.

In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.

The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.

In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.

The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk, which can store program codes.

The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

24页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种设备视图管理方法、装置和系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!