Kirby.com Cloudinary plugin with crop()

Hello,

I tried the kirby.com Cloudinary Plugin which seemed to work well but it’s look like when I use the crop() method it keep the original URL and then resize so the image is distorted, flattened.

My use case is for making thumbnails (croped to the top) for project screenshots, and it’s open the original file when clicking.
Here my simplified snippet which looking for a files field with multiple images:

<?php
// Project screen thumbnail sizes
$thumb_width = 540;
$thumb_height = 350;
?>

<?php foreach ($page->gallery()->toFiles() as $thumb) : ?>
<img  src="<?= $thumb->crop($thumb_width, $thumb_height, 'top')->url(); ?>"
      srcset="<?= "{$thumb->crop($thumb_width * 2, $thumb_height * 2, 'top')->url()} 2x"; ?>"
      width="<?= $thumb_width; ?>"
      height="<?= $thumb_height; ?>"
      alt=""
      loading="lazy">
<?php endforeach; ?>

What’s missing here?

Thanks!

Maybe you can find the answer in this unpublished recipe here: https://github.com/getkirby/getkirby.com/pull/899/files

(Although, that’s KeyCDN, not cloudinary…)

1 Like

Hello, thanks for your reply. I finally got some time to do it but I have an error:
Call to undefined method Kirby\Toolkit\Str::beginsWith()

Is that something new to 3.5 ? I can’t find its reference in the doc.
I’m running the 3.4.5, will update soon!

EDIT: ah, isn’t startsWith() instead ?

Yes, beginsWith() doesn’t exist.

Fixed.