Java backend implements image compression technology and java backend Image Compression
Today I want to talk about the image compression technology. Why do we need to use image compression? Isn't it enough to upload images? Yes, this can be said a few years ago, because a few years ago there was not such a large concurrency, nor is it so concerned about performance.
Nowadays, there are many mobile phones. Many people access networks or apps through their mobile phones. When calling interfaces, they will certainly browse images more or less, especially when they are disconnected from wifi, you can see that many software displays a thumbnail, which is a compressed image. After you click it, it will be enlarged, as shown below:
This approach can minimize the image display pressure on the mobile phone end, because an image may be several hundred kb or several megabytes for the uploader, in this way, the pressure on the mobile phone end will be relatively high, but it will also consume a lot of traffic, so in today's mobile Internet, we must do a good job of such image compression processing.
No, this will save a lot of traffic after compression.
I have encountered two types of Image Compression currently. The first one is not mentioned. It is implemented using java swing. It is not recommended. The second one is recommended, that is, the thumbnailator component, which is very practical, and has been updating
Add the following configuration in pom:
<!-- image util -->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>${thumbnailator.version}</version>
</dependency>
Proportional scaling by length and width
In addition, this component also provides functions such as image quality improvement or reduction, watermarking and rotation. If you are interested, you may wish to have a try!