I. Java uses google's thumbnailator tool to process image compression watermarks,

Source: Internet
Author: User

I. Java uses google's thumbnailator tool to process image compression watermarks,
Thumbnailator is a good open-source image tool: Add the following jar package to pom

<! -- Start -->

<Dependency>
<GroupId> net. coobird </groupId>
<ArtifactId> thumbnailator </artifactId>
<Version> 0.4.8 </version>
</Dependency> <! -- Image thumbnail image compression watermark end -->

 

Then, only one line of code is required for compression and watermarking.
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 * Image Compression * @ author HONGLINCHEN * @ since JDK 1.8 */public class ImgCompress {public static void main (String [] args) throw S IOException {// The first parameter of the compressed image is the path after the source image path which is the compressed output path Thumbnails. of ("C: \ Users \ HONGLINCHEN \ Desktop \ 23.jpg "). size (600,600 ). outputQuality (0.8f ). toFile ("C: \ Users \ HONGLINCHEN \ Desktop \ 2.jpg"); // Add a watermark BufferedImage watermarkImage = ImageIO to the image. read (new File ("C: \ Users \ HONGLINCHEN \ Desktop \ 1.jpg"); // The first parameter is the watermark position, and the second parameter is the cached data of the watermark image; the third parameter is transparency. Thumbnails. of ("C: \ Users \ HONGLINCHEN \ Desktop \ 23.jpg "). scaling (0.8 ). watermark (Positions. BOTTOM_RIGHT, watermarkImage, 0.5f ). toFile ("C: \ Users \ HONGLINCHEN \ Desktop \ 3.jpg ");}}

Github source code:Https://github.com/moyiblog/thumbnailator

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.