Kirby unable to create thumbnails for large images (?)

So I have a website with many large images and I have it set up to create smaller thumbnails for responsive images.

I am not sure how to troubleshoot it, but it seems like Kirby is having trouble creating thumbnails sometimes.

You can see this at Projecten | DAVL Studio | Architectuur, Ontwikkeling, Design. The project ‘Kiosk Frederik Hendriklaan’ is a good example. Kirby is supposed to make a thumbnail that is 420px wide, and it does create an image file, but it’s the full size: https://davlstudio.com/media/pages/projecten/kiosk-frederik-hendriklaan/eb166b274c-1738337938/kiosk_pure-flowers_01-420x-q80.jpg

Could it be that Kirby runs out of memory, or something like that? Am I trying to create too many thumbnails? The website is hosted on a shared hosting platform, so I thought perhaps it cannot handle all of these large images very well.

Locally, where I am using MAMP, it seems to work as it should, creating thumbnails of the correct size.

If it helps, this is the code I am using to generate responsive images:

<?php

// Define default sizes
$sizes = "(min-width: 1080px) 50vw, calc(100vw - 2em)";

// Set target use to default if not specified
if (!isset($targetUse)):
    $targetUse = "default";
    // $sizes = "(min-width: 1080px) 50vw, calc(100vw - 2em)";
else:
    // Define size rules based on specific target uses
    switch ($targetUse):
        case 'articleExcerpt':
            $sizes = "(min-width: 1920px) 332px,
                      (min-width: 1583px) 475px,
                      (min-width: 1540px) 33vw,
                      (min-width: 420px) 50vw,
                      100vw";
            break;
        case 'projectsThumbnail':
            $sizes = "(min-width: 1920px) 16.67vw,
                      (min-width: 1540px) 25vw,
                      (min-width: 1080px) 33vw,
                      50vw";
            break;
        case 'project':
            $sizes = "(min-width: 1540px) 326px,
                      (min-width: 1080px) 25vw,
                      (min-width: 420px) 50vw, 
                      100vw";
            break;
        case 'articleImage':
            $sizes = "(min-width: 1584px) 744px,
                      (min-width: 1080px) 50vw,
                      100vw";
            break;
        case 'spanTwelve':
            $sizes = "(min-width: 1584px) 1520px, 100vw";
            break;
        case 'spanSix':
            $sizes = "(min-width: 1584px) 744px,
                      (min-width: 1080px) 50vw,
                      100vw";
            break;
        case 'spanFour':
            $sizes = "(min-width: 1584px) 501px,
                      (min-width: 1080px) 33vw,
                      100vw";
            break;
        case 'spanThree':
            $sizes = "(min-width: 1584px) 374px,
                      (min-width: 1540px) 25vw,
                      (min-width: 1080px) 50vw,
                      100vw";
            break;
        case 'slide':
            $sizes = "100vw";
            break;
    endswitch;
endif;

// Define size mapping for responsive images
$sizeMap = [
    'XXL'   => 2560,
    'XL'    => 1920,
    'L'     => 1540,
    'M'     => 1080,
    'TQM'   => 750,
    'halfM' => 540,
    'S'     => 420,
    'XS'    => 360,
];

// Set default image size for srcset
$srcsetSize = 'S';

// Determine the optimal image size for srcset based on the target size or image width
foreach ($sizeMap as $sizeName => $sizeValue):
    if ($image->width() > $sizeValue):
        $srcsetSize = $sizeName;
        break;
    endif;
endforeach;

?>

<picture class="image">

  <?php if ($targetUse == 'slide'): ?>
    <?php // AVIF and WebP sources for slide images ?>
    <source srcset="<?= $image->srcset('avif') ?>" sizes="100vw" type="image/avif">
    <source srcset="<?= $image->srcset('webp') ?>" sizes="100vw" type="image/webp">
  <?php endif; ?>

  <?php //  Fallback image with lazy loading ?>
  <img src="<?= $image->url() ?>"
       srcset="<?= $image->srcset($srcsetSize) ?>"
       sizes="<?= $sizes ?>"
       alt="<?= $image->alt() ?>"
       width="<?= $image->width() ?>"
       height="<?= $image->height() ?>"
       loading="lazy"
       style="
           aspect-ratio: <?= $ratio ?? 'auto' ?>;
           object-fit: <?= ($contain ?? false) ? 'cover' : 'contain' ?>;
       ">
</picture>

And this is how it’s used in the projects.php template:

<?php snippet('header') ?>

<?php foreach ($page->children()->listed() as $project): ?>
<a href="<?= $project->url() ?>" class="projects-list-link">
  <figure class="projects-list-image">

    <?php snippet('image', 
      [
        'image' => $project->images()->sortBy('sort', 'asc', 'filename', 'asc')->first(),
        'targetUse' => 'projectsThumbnail'
      ]) ?>

    <h2 class="projects-list-title">
      <?= $project->title()->esc() ?>
    </h2>
  </figure>
</a>
<?php endforeach ?>

<?php snippet('footer') ?>

I hope this is enough information to be able to diagnose the problem!

What thumbdriver are you using? A cause of this can be setting to thumb driver to IM (ImageMagic) without it being installed or enabled on the sever. You can end up with the orginal image being passed through to the media folder with the expected file name for the desired size, but its actually the origainal.

Check your PHP config if thats the case. How big in physical size (width/height) and file size (kn/megabytes) are the original source images? Set the PHP ini to give it as much RAM as you can.

Thanks for your reply!

You can end up with the orginal image being passed through to the media folder with the expected file name for the desired size, but its actually the origainal.

It does seem like this is happening.

I haven’t actually set a driver for the live version of the website, but I did set one locally. This is config.localhost.php: config.localhost.php - Pastebin.com and this is config.davlstudio.com.php: config.davlstudio.com.php - Pastebin.com.

I am not sure I am able to increase the RAM that PHP can use, given that I am on shared hosting currently.

An example of an original file in terms of size is this one: https://davlstudio.com/media/pages/projecten/arrangement-heeg/cc4d17727a-1738338006/2022-09-02_heeg-0003b.jpg. It’s 6000 x 4000 px and it was 3.8 MB originally.

How many of the images are actually affected by this, looks like the thumbs are generated correctly for most images, though?

Yes, most seem to be generated correctly. It seems to only happen to some images.

I tried deleting the media folder for this project: DAVL Studio | Architectuur, Ontwikkeling, Design | Arrangement Heeg and it successfully made the 420 px wide thumbnail, but not the 360 px wide thumbnail.

https://davlstudio.com/media/pages/projecten/arrangement-heeg/cc4d17727a-1738338006/2022-09-02_heeg-0003b-420x-q80.jpg vs. https://davlstudio.com/media/pages/projecten/arrangement-heeg/cc4d17727a-1738338006/2022-09-02_heeg-0003b-360x-q80.jpg.

Sometimes, when creating a page, I also get a 500-something server error. I am increasingly thinking the server is not powerful enough.

It seems like I can‘t change a lot of the PHP settings, but I can choose to run PHP as either “FPM application served by Apache” or “dedicated FPM application served by Apache”. Does that make a difference at all?