Thumbnailator application description for Java thumbnail generation library,

Source: Internet
Author: User

Thumbnailator application description for Java thumbnail generation library,

Thumbnailator is a library for generating thumbnails with smoother Java interfaces. The scale-down process is simplified by using the API to provide existing image files and thumbnails of image objects. Two or three lines of code can generate thumbnails from existing images and allow the generation of fine-tuned thumbnails, at the same time, the minimum amount of code to be written is maintained. You can also generate thumbnails in batches based on a directory.

Version: thumbnailator-0.4.2.jar

The source image is as follows:


1. Zoom in or out the specified size
Copy codeThe Code is as follows:
// Size (width and height)

/*
* If the image horizontal ratio is smaller than 200, the aspect ratio is smaller than 300, and the image remains unchanged.
* If the image horizontal ratio is smaller than 200, the aspect ratio is greater than 300, and the height is reduced to 300, the image proportion remains unchanged.
* If the image size is larger than 200, the image height is smaller than 300, and the image size is reduced to 200, the image size remains unchanged.
* If the image size is larger than 200, the image height is greater than 300, and the image size decreases proportionally. The horizontal value is 200 or the height is 300.
*/
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (200,300)
. ToFile ("c:/a380_200x300.jpg ");

Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (2560,204 8)
. ToFile ("c:/a380_2560x2048.jpg ");


2. Scale by proportion
Copy codeThe Code is as follows:
// Scale (proportion)
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Scale (0.25f)
. ToFile ("c:/a380_252.16.jpg ");

Thumbnails. of ("images/a380_1280x1024.jpg ")
. Scale (1.10f)
. ToFile ("c:/a380_1102.16.jpg ");


3. scale according to the specified size instead of the ratio.
Copy codeThe Code is as follows:
// KeepAspectRatio (false) is scaled proportionally by default.
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (200,200)
. KeepAspectRatio (false)
. ToFile ("c:/a380_200x200.jpg ");


4. Rotate
Copy codeThe Code is as follows:
// Rotate (angle), positive: Negative clockwise: counter-clockwise
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. Rotate (90)
. ToFile ("c:/a380_rotate000090.jpg ");

Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. Rotate (-90)
. ToFile ("c:/a380_rotate-90.jpg ");



5. Watermarks
Copy codeThe Code is as follows:
// Watermark (Position, watermark image, transparency)
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. Watermark (Positions. BOTTOM_RIGHT, ImageIO. read (new File ("images/watermark.png"), 0.5f)
. OutputQuality (0.8f)
. ToFile ("c:/a380_watermark_bottom_right.jpg ");

Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. Watermark (Positions. CENTER, ImageIO. read (new File ("images/watermark.png"), 0.5f)
. OutputQuality (0.8f)
. ToFile ("c:/a380_watermark_center.jpg ");



6. Cropping
Copy codeThe Code is as follows:
// SourceRegion ()

// Image center 400*400
Thumbnails. of ("images/a380_1280x1024.jpg ")
. SourceRegion (Positions. CENTER, 400,400)
. Size (200,200)
. KeepAspectRatio (false)
. ToFile ("c:/a380_region_center.jpg ");

// The lower right corner of the image is 400*400.
Thumbnails. of ("images/a380_1280x1024.jpg ")
. SourceRegion (Positions. BOTTOM_RIGHT, 400,400)
. Size (200,200)
. KeepAspectRatio (false)
. ToFile ("c:/a380_region_bootom_right.jpg ");

// Specify coordinates
Thumbnails. of ("images/a380_1280x1024.jpg ")
. SourceRegion (600,500,400,400)
. Size (200,200)
. KeepAspectRatio (false)
. ToFile ("c:/a380_region_coord.jpg ");



7. Convert the image format
Copy codeThe Code is as follows:
// OutputFormat (image format)
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. OutputFormat ("png ")
. ToFile ("c:/a380_1280x1024.png ");

Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. OutputFormat ("gif ")
. ToFile ("c:/a380_1280x1024.gif ");


8. output to OutputStream
Copy codeThe Code is as follows:
// ToOutputStream (Stream object)
OutputStream OS = new FileOutputStream ("c:/a380_1280x1024_OutputStream.png ");
Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. ToOutputStream (OS );


9. output to BufferedImage
Copy codeThe Code is as follows:
// AsBufferedImage () returns BufferedImage
BufferedImage thumbnail = Thumbnails. of ("images/a380_1280x1024.jpg ")
. Size (4, 1280,102)
. AsBufferedImage ();
ImageIO. write (thumbnail, "jpg", new File ("c:/a380_1280x1024_BufferedImage.jpg "));


The size is 20.7 KB.

The size is 1.1 KB.

The size is 2.3 KB.

The size is 2.2 KB.

The size is 23.2 KB.

The size is 23.3 KB.

The size is 27.9 KB.

Size: 27 KB

Related Article

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.