Can I combine the new srcset() with crop()?

#1

I’m trying something like this:

<?php $articleimage = $articlelist->images()->first()->crop(500,300)?>
      <img
          srcset="<?= $articleimage->srcset()?>"
          class="lazyload"
          data-sizes="auto"
          alt="<?= $articlelist->title()?>"/>

unfortunately this doesn’t work.

0 Likes

#2

No, that doesn’t work. You can’t create thumbs from thumbs.

0 Likes

#3

Hm ok. Is there a way to implement the “crop function” in the “srcset”? Or does anyone have any other idea how I can solve this?

0 Likes

#4

I tried some things yesterday but they didn’t work. Can’t think of a workaround for the moment apart from creating a custom file method that does the same we would’ve done to create the srcset before the srcset method was introduced.

0 Likes

#5

Need the same thing. There are always images, that need to be cropped. One possible solution is to use css object-fit: cover css property for image. This way you can “cut” image without actually cutting it. Con is that you have bigger file size, than you could, if it was actually cut, but on the other hand, if you resize image with srcset, it’s still smaller.

0 Likes

#6

As I said above, the alternative is to create the srcset manually from the original file…

0 Likes