Java Galleria IO thumbnail reduce aspect ratio formula

335 views Asked by At

I have an image galleria using Galleria IO. 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.

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? 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?

1

There are 1 answers

0
Harald K On BEST ANSWER

Aspect ratio, is calculated simply as 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.

As an example, for your 320x210 image the aspect ratio is:

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):

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