https://twill.io logo
Art directed responsive image rendering
# ❓questions
n
Hello, How are twill image crops applied? I have different crops defined for desktop, tablet and mobile. But I only see desktop displayed in all cases. I display the images with 'desktop' crop key (
$item->image('picture', 'desktop')
), is this why is only displays that crop mode? I tried it with
tablet
and
mobile
but it still only displays the
desktop
version.
i
@Nechalon are you familiar with art directed responsive images with the tag? That's how multiple crops are supposed to be used. You may want to use #873445927740903475 if you are not familiar with how to implement it
n
I see, I didnt use picture tags before, how can I display all versions of the pictures with twill-image?
I see that the documentation is here, im not sure what to try from here
i
check the
preset
section
If you feel like that's still too much to learn, here's a quick example of how to implement it without the package:
Copy code
<picture>
    <source srcset="{{ $item->image('medias_field_name', 'crop_key', ['w' => 200] }} 200w, {{ $item->image('medias_field_name', 'crop_key', ['w' => 400] }} 400w, ...<as many width as you need depending on how large the image is rendering at in your frontend>" sizes="<media query defining when to use this source and a value defining how much of the viewport width this image takes eg. 50vw>">
<as many sources as you have crop keys>
<img tag with a placeholder image and width height attributes or a ratio box to avoid layout shifts>
</picture>
n
Copy code
<picture class="figures col-12 col-md-{{ App\Helpers\Course::colCount(count($block->images('gallery', 'desktop'))) }} mb-4">
    <source media="(max-width: 768px)" srcset="{{ $image['image_url']['mobile'] }}"> 
    <source media="(min-width: 768px) and (max-width: 992px)" srcset="{{ $image['image_url']['tablet'] }}">
    <source media="(min-width: 992px)" srcset="{{ $image['image_url']['desktop'] }}">
    <img src="{{ $image['image_url']['desktop'] }}" class="img-fluid">
</picture>
This did the trick! Thanks @ifox
2 Views