Java thumbnailator the image by zooming, cropping, adding watermarks and so on.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.