简体   繁体   English

Java Galleria IO缩略图降低宽高比公式

[英]Java Galleria IO thumbnail reduce aspect ratio formula

I have an image galleria using Galleria IO. 我有一个使用Galleria IO的图像Galleria。 When the plugin adds the images of several sizes, they resize each one like this: 当插件添加多种尺寸的图像时,它们会像这样调整每个尺寸:

Original Size[width-height]       Thumbnail[width-height]
* 320x210                         *122x80
* 450x600                         *60x80 
* 600x525                         *91x80
* 600x885                         *54x80
* 741x694                         *85x80

as you can see the heights is always 80 . 如您所见,高度始终为80

My question arises I need to translate this images into a report the same images in the galleria. 我的问题出现了,我需要将这些图像转换成与画廊相同图像的报告。 And I need to resize all the images, because I would like translate the same thumbnails size into the report. 我需要调整所有图像的大小,因为我想将相同的缩略图大小转换为报告。

I was wondering how to know the galleria IO ratio to resizes how they accomplish that? 我想知道如何知道回廊的IO比例以调整其实现方式? I would like to have the same ratio when I resize the others images in the database. 当我调整数据库中其他图像的大小时,我希望具有相同的比率。

Or there is some routine in Java to do the same or so? 还是Java中有一些例程可以执行相同的操作?

Aspect ratio, is calculated simply as width / height . 长宽比可以简单地作为width / height来计算。 Given one dimension in the result size, you can calculate the other. 给定结果大小的一个维度,您可以计算另一个维度。 If the height is always 80, the aspect ratio varies, but it's easy to calculate for each image. 如果高度始终为80,则宽高比会发生变化,但是很容易为每个图像进行计算。

As an example, for your 320x210 image the aspect ratio is: 例如,对于您的320x210图像,宽高比为:

aspect ratio = w / h = 320 / 210 = 1.5238.. 

Now, given that the height is 80, you can compute width like this (we round to the nearest integer): 现在,假设高度为80,您可以像这样计算宽度(我们四舍五入为最接近的整数):

w = h * aspect ratio = 80 * 1.5238.. = 121.904.. => 122

Using the same formula, you could also compute the height, given a width, like: 使用相同的公式,您还可以计算给定宽度的高度,例如:

h = w / aspect ratio = 122 / 1.5238.. = 80.064.. => 80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM