Package Com.test.image;import static Org.junit.assert.*;import Java.io.file;import Javax.imageio.imageio;import Net.coobird.thumbnailator.thumbnails;import Net.coobird.thumbnailator.geometry.positions;import org.junit.Test; public class Imagetest {/** * Scales by the specified size by scale * @throws Exception */@Testpublic void Testone () throws Exception {//file fil E = new File ("image/1.jpg");//system.out.println (File.exists ()); Thumbnails.of ("Image/1.jpg"). Size ($). ToFile ("image/1_200x300.jpg"); /*** * Scaled by a specified scale * @throws Exception */@Testpublic void Testtwo () throws Exception {thumbnails.of ("image/1.jpg"). Scale (0 .25f). ToFile ("Image/a_0.25%.jpg");} /*** * Scaling According to the specified size is not proportional * @throws Exception */@Testpublic void Testthree () throws Exception {thumbnails.of ("image/1.jpg") . Size (200, 300)//setting whether to proportionally false the picture may shape by default true. Keepaspectratio (False). ToFile ("image/1_200x300_no.jpg"); /** * Add watermark (as if you can only add a picture watermark?) ) * @throws Exception */@Testpublic void Testfour () throws Exception {thumbnails.of ("image/1.jpg"). Size (1920, 1080)//must be set to size or throw an exception. Watermark (Positions.bottom_right,imageio.read ("New File") ("Image/a_0.25%.jpg"), 0.5f)// The higher the output quality the larger the picture. Outputquality (1.0f). ToFile ("Image/wt.jpg");} /*** * cropping * @throws Exception */@Testpublic void testfive () throws Exception {thumbnails.of ("image/1.jpg")//starting from the original where clipping cuts How many. sourceregion (Positions.center, 400, 400)//the size of the new figure. ($, $). ToFile ("Image/crop.jpg");} /** * Change Picture format * @throws Exception */@Testpublic void Testsix () throws Exception {thumbnails.of ("image/1.jpg"). Size (1920, 10 ). OutputFormat ("PNG"). ToFile ("Image/1_png.png");} @Testpublic void TestName () throws Exception {System.out.println (System.getproperty ("User.dir"));}}
Java thumbnailator the image by zooming, cropping, adding watermarks and so on.