Thumbnailator is a very good picture of how to use open Source tools: Add the following jar packages to the POM
<!--picture thumbnail image compression watermark start-
<Dependency>
<groupId>Net.coobird</groupId>
<Artifactid>Thumbnailator</Artifactid>
<version>0.4.8</version>
</Dependency><!--picture thumbnail image compression watermark end -
Then the compression and watermark only need one line of code to fix
package Com.shallowmemory.test;import net.coobird.thumbnailator.Thumbnails; Import Net.coobird.thumbnailator.geometry.positions;import Javax.imageio.imageio;import Java.awt.image.bufferedimage;import java.io.file;import java.io.ioexception;/*** Created by HONGLINCHEN on 2017/10/31 11:00* image compression * @author honglinchen* @since JDK 1.8*/public class Imgcompress {public static void main (string[] args) throws IOException {//Compress picture The first parameter is the path after the original path is the output path after compression thumbnails.of ("C:\Users\HONGLINCHEN\Desktop\23.jpg"). Size (600,600) . outputquality (0.8f). ToFile ("C:\Users\HONGLINCHEN\Desktop\2.jpg");//Add watermark to the picture bufferedimage Watermarkimage = Imageio.read (New File ("C:\Users\HONGLINCHEN\Desktop\1.jpg"));//The first parameter is the location of the watermark, the second parameter is the cached data for the watermark picture, and the third parameter is transparency. Thumbnails.of ("C:\Users\HONGLINCHEN\Desktop\23.jpg"). Scale (0.8). Watermark (Positions.bottom_right, Watermarkimage, 0.5f). ToFile ("C:\Users\HONGLINCHEN\Desktop\3.jpg");}}
GitHub Source:Https://github.com/moyiblog/thumbnailator
A: Java using Google's Thumbnailator tool to compress images, such as image processing