[英]Using Thumbnailator, can i make thumbnail with same height and width regardless the image size
In Thumbnailator , i am making thumbnails.在Thumbnailator 中,我正在制作缩略图。
If image size is 400*300 and if i do following thing,如果图像大小为 400*300 并且我执行以下操作,
Thumbnails.of(new File("original.jpg"))
.size(160, 160)
.toFile(new File("thumbnail.jpg"));
it create thumbnail of 160*120.它创建 160*120 的缩略图。
What i want is if i upload 400*300 image, it will center zoom so that i will become 300*300 and then it will thumbnail.我想要的是,如果我上传 400*300 的图像,它会居中缩放,这样我就会变成 300*300,然后它会缩略图。
I gone through the documentation, Even i posted same thing over there in comment but no luck.我浏览了文档,即使我在评论中发布了同样的内容,但没有运气。
Sounds like a job for the sourceRegion
method which can be used to specify the region from which the thumbnail should be produced:听起来像是sourceRegion
方法的一项工作,该方法可用于指定应从中生成缩略图的区域:
In your particular case, you'll want to try the following:在您的特定情况下,您需要尝试以下操作:
Thumbnails.of(new File("original.jpg"))
.sourceRegion(Positions.CENTER, 300, 300)
.size(160, 160)
.toFile(new File("thumbnail.jpg"));
The above code will:上面的代码将:
original.jpg
,打开original.jpg
,thumbnail.jpg
.写入thumbnail.jpg
。 It's possible to select different regions of the original image by changing Positions.CENTER
to, for example, Positions.TOP_LEFT
.有可能通过改变选择的原始图像的不同区域Positions.CENTER
,例如, Positions.TOP_LEFT
。 For a complete list of pre-defined choices, please look at the documentation for the Positions
enum.有关预定义选项的完整列表,请查看Positions
枚举的文档。
The following are some links to the Thumbnailator API documentation which may be of interest:以下是您可能感兴趣的缩略图 API 文档的一些链接:
sourceRegion(int, int, int, int)
method sourceRegion(int, int, int, int)
方法
sourceRegion(Position, int, int)
method sourceRegion(Position, int, int)
方法
Position
object as shown in the example code above.使用Position
对象使用相对定位,如上面的示例代码所示。sourceRegion(Rectangle)
method sourceRegion(Rectangle)
方法
java.awt.Rectangle
object.用于使用java.awt.Rectangle
对象指定创建缩略图的确切区域。Position
enum Position
枚举
Disclaimer: I am the maintainer of the Thumbnailator library.免责声明:我是缩略图库的维护者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.