What Java library should I use for image clipping / letterboxing?

I am looking for a Java library for image clipping / resizing I planned to use jmagick, but I haven't maintained it since 2009

Is this the best library to use? Any suggestions?!

edit

One thing I want to do is be able to fill the image to resize and crop it That is, if I have 4 × 2 image, and I want to make it square, I want to make it 4 × 4. Each side is filled with black or white Does this have a name in image processing? Is it a feature that comes with any library?

Solution

I maintain thumbnail, a thumbnail generation library for Java, which provides a method to adjust the image size and some simple image processing through the easy-to-use fluent API

One of the features provided by the thumbnail is the canvas filter, which can crop and fill (or) the generated thumbnails letter@R_277_2419 @ing).

Fill image

For example, filling an image with a canvas filter can be achieved in the following ways:

Thumbnails.of("path/to/image.jpg")
  .size(150,150)
  .addFilter(new Canvas(150,150,Positions.CENTER,Color.blue))
  .toFile("path/to/padded-image.jpg");

General:

>Take the original image and reduce it to 150 x 150 by size. > Then, the other filtering steps specified by the addfilter method will add a blue fill (using color. Blue) to generate a final image with a size of 150 x 150. > Save the generated thumbnail to path / to / padded image jpg.

Using the above code on portrait photos will produce the following results:

padded image http://coobird.net/img/so-8150276-padding.jpg

Crop image

Cropping an image using the canvas filter can be achieved in the following ways:

Thumbnails.of("path/to/image.jpg")
  .size(150,150)
  .addFilter(new Canvas(100,100,Positions.TOP_RIGHT,true))
  .toFile("path/to/cropped-image.jpg");

The above code will:

>Take the original image and reduce it to 150 x 150 by size. > Then, an additional filtering step will crop out a 100 x 100 area from the upper right corner of the resized image (the real parameter present in the canvas constructor call indicates that the image should be cropped if it is larger than the specified size.) > Save the generated thumbnail to path / to / cropped image jpg.

An example of running the above code is as follows:

cropped image http://coobird.net/img/so-8150276-cropping.jpg

At present, some functions require clipping as an integral part of the thumbnail API, so I plan to add a clipping method in the future, which can reduce the need to call the addfilter method in most cases

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>