How to load images in smaller size while keeping aspect ratio and not cutting parts of it off?
Hello,
I am trying display images with a smaller width that I uploaded in my CMS but without any crop. So for example a logo that is 2000px by 3000px I want to display it with a width of 300px while keeping correct aspect ratio and without cutting parts of the image off. It's not really clear for me in the documentation how to do that.
Currently I have this code:
@foreach($logos->imageObjects('image', 'default') as $logo)
<div class="swiper-slide d-flex">
<a href="{{ $logos->image('image', 'default', ['w' => 300, 'fit' => 'stretch'], false, false, $logo) }}" class="card-img d-flex align-items-center p-3" data-gtf-mfp="true"
data-gallery-id="03">
<img src="{{ $logos->image('image', 'default', ['w' => 300, 'fit' => 'stretch'], false, false, $logo) }}" loading="lazy" alt="product gallery" class="w-100 h-auto">
</a>
</div>
@endforeach
With this code the width is indeed 300 but parts of the image are cut off. Example:
I'm just using twill out of the box, no extra installed image or media plugins.
3 Replies
Size - Glide
Wonderfully easy on-demand image manipulation library with an HTTP based API.
You can test with other params other than stretch
Thanks!