1. Hammur
  2. Sherlock Holmes
  3. Commercial Templates
  4. Tuesday, 25 August 2020
  5.  Subscribe via email
Hi, using the Thumb Gallery module, the thumbnail images are scaled to fit the dimension specified in the module parameters.

If the images have a different aspect ratio, they however get distorted.
So I'd like to ask if its possible to modify how the thumbnail are resized to its container by some CSS?
I.e. so that thumbnails get cropped to keep their the aspect ratio instead of just fitted?

I tried to apply following css but without any effect:
.j51thumbs .j51Box img {
object-fit: cover;
}
Example of what I'm trying to do with this property can be seen here object-fit.

My idea is to have a simple image gallery where all thumbnails are same size but don't get distorted if the aspect ratio doesn't fit.
The user can then of course click them to see the full size.

If this is not possible, I might give Image Hover module a go, it keeps the aspect ratios but ideally I'd like to have the thumbnails to be same size instead of varying size due to possible different aspect ratios.
Accepted Answer Pending Moderation
0
Votes
Undo
I had the same problem so what I've done is chage the resize.image.class.php file which generates the thumbnails.
When I set 200px width and 200px height in the module the thumbs are now generated to these 200px/200px fixed width and height but keeps the aspect ratio.
If the height for example is then bigger than 200px (because of the aspect ratio) the thumbnail only 'crops' out the needed 200px

Diff (left old/right my updated version): https://www.diffchecker.com/4GxLWgkA
quick & dirty hack - in theory this $crop true/false could be a new option in the module and so on... but don't have the time for that at the moment

my edited resize.image.class.php file (overwrite /modules/mod_j51thumbsgallery/resize.image.class.php) attached


This code doesn't work with PHP 8.0, `imagedestroy` crashes with an empty argument. Y coordinate offset is missing too. I changed original file like this:
// Find optimal resize coefficient
$resize_coef = max($this->new_width / $width, $this->new_height / $height);
// Calculate coordinate offsets
$src_x = ($width - $this->new_width / $resize_coef) / 2;
$src_y = ($height - $this->new_height / $resize_coef) / 2;
// Calculate used source image sizes
$width = $this->new_width / $resize_coef;
$height = $this->new_height / $resize_coef;

ImageCopyResampled($image_c, $new_image, 0, 0, $src_x, $src_y, $this->new_width, $this->new_height, $width, $height);


Attached updated file.
Attachments (1)
  1. more than a month ago
  2. Commercial Templates
  3. # 1
Accepted Answer Pending Moderation
0
Votes
Undo
I had the same problem so what I've done is chage the resize.image.class.php file which generates the thumbnails.
When I set 200px width and 200px height in the module the thumbs are now generated to these 200px/200px fixed width and height but keeps the aspect ratio.
If the height for example is then bigger than 200px (because of the aspect ratio) the thumbnail only 'crops' out the needed 200px

Diff (left old/right my updated version): https://www.diffchecker.com/4GxLWgkA
quick & dirty hack - in theory this $crop true/false could be a new option in the module and so on... but don't have the time for that at the moment

my edited resize.image.class.php file (overwrite /modules/mod_j51thumbsgallery/resize.image.class.php) attached
Attachments (2)
  1. more than a month ago
  2. Commercial Templates
  3. # 2
Accepted Answer Pending Moderation
0
Votes
Undo
Hello

Would you have a URL to an example of your thumbs gallery module including images of various sizes?

Ciaran
  1. more than a month ago
  2. Commercial Templates
  3. # 3
Accepted Answer Pending Moderation
0
Votes
Undo
Hi Ciaran,

Please see my test side using the demo installer, where I've added some additional images shown in the 3rd row to the "ThumbsGallery Example" module:
References
  1. https://test.konsult.fo/amelia/index.php/features/thumbs-gallery-module
  1. more than a month ago
  2. Commercial Templates
  3. # 4
Accepted Answer Pending Moderation
0
Votes
Undo
Thank you

The issue here is that the ThumbsGallery module creates the thumbs on the fly and crops all images to the same dimensions as set in the module settings. Having you considered using the ImageHover module instead which I believe will be a better fit for your purpose?

Ciaran
  1. more than a month ago
  2. Commercial Templates
  3. # 5
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!

Join Our Newsletter

* indicates required
We respect your privacy and do not tolerate spam and will never sell, rent, lease or give away your information (name, email, number, etc.) to any third party. Nor will we send you unsolicited email.
Joomla51 - Mullaghmore, Co. Sligo, Ireland
Joomla51.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by
Open Source Matters
the trademark holder in the United States and other countries.

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.

Ok