Thumb generation bugs (front and backend) – only works when you reload the browser

Hey!:waving_hand:

I’m having trouble with a Kirby installation on a live server. Thumbs only appear if the page is loaded twice. This is what I get: :backhand_index_pointing_down:

When I first load the page, I get a 404 error for that image, but after reloading, it’s there. :white_check_mark:
And I ALSO get this in the backend:

I’m not sure why this is the case. However, I suggest that, at least for the front end, it may come from a less powerful web server. I’m embedding the images like this:

              <img 
              src="<?= esc($imageFile->crop(2560, 1440, 50)->url(), 'attr') ?>" 
              srcset="<?= $imageFile->srcset('stage') ?>"
              alt="<?= esc($imageFile->alt(), 'attr') ?>" 
              class="w-full transition h-full object-cover <?= $filterActive ? $filterBlendMode : '' ?>" 
              style="object-position: <?= esc($focalX, 'attr') ?> <?= esc($focalY, 'attr') ?>;" 
                />

So there is quite a lot to calculate. The server comes with the following preinstalled PHP extensions: GD and ImageMagick. Check those settings:

Some core php settings:

I know that I can set the thumb driver in the config, but that doesn’t seem to make a difference. I defined those settings in my config.php :

      'thumbs' => [
        'driver' => 'im',
        'srcsets' => [
            'default' => [
              // width values come from tailwind (640, 768, 1024, 1280, 1440 – 1440 is modified though, check main.css)
              '640w' => ['width' => 640, 'quality' => 50, 'format' => 'jpeg'],   // sm
              '768w' => ['width' => 900, 'quality' => 50, 'format' => 'jpeg'],   // md
              '1024w' => ['width' => 1200, 'quality' => 50, 'format' => 'jpeg'], // lg
              '1280w' => ['width' => 1500, 'quality' => 50, 'format' => 'jpeg'], // xl
              '1440w' => ['width' => 2560, 'quality' => 50, 'format' => 'jpeg'], // 2xl (adjusted to 1440px)
            ],
            'stage' => [
              '640w' => ['width' => 640, 'quality' => 50, 'format' => 'jpeg'],   // sm
              '768w' => ['width' => 900, 'quality' => 50, 'format' => 'jpeg'],   // md
              '1024w' => ['width' => 1200, 'quality' => 50, 'format' => 'jpeg'], // lg
              '1280w' => ['width' => 1500, 'quality' => 50, 'format' => 'jpeg'], // xl
              '1440w' => ['width' => 2560, 'quality' => 50, 'format' => 'jpeg'], // 2xl (adjusted to 1440px)
            ],
            'stagehalf' => [
              '640w' => ['width' => 1024, 'quality' => 50],   // sm
              '768w' => ['width' => 1280, 'quality' => 50],   // md
              '1024w' => ['width' => 1280, 'quality' => 50], // lg
              '1280w' => ['width' => 1280, 'quality' => 50], // xl
              '1440w' => ['width' => 1280, 'quality' => 50], // 2xl (adjusted to 1440px)
            ],
            'columnimage' => [
              '640w' => ['width' => 640, 'quality' => 50, 'format' => 'jpeg'],   // sm
              '768w' => ['width' => 980, 'quality' => 50, 'format' => 'jpeg'],   // md
              '1024w' => ['width' => 640, 'quality' => 50, 'format' => 'jpeg'], // lg
              '1280w' => ['width' => 640, 'quality' => 50, 'format' => 'jpeg'], // xl
              '1440w' => ['width' => 1024, 'quality' => 50, 'format' => 'jpeg'], // 2xl (adjusted to 1440px)
            ],
        ]
      ],      

If anyone has any advice, I would be very grateful. :slight_smile:
All the best!

Imagick != ImageMagick

Please set the driver to gd, if you don’t have ImageMagick command line tool installed on the server. Imagick, however, is a PHP extension. I’d also increase the max_execution_time value in php.ini and the memory_limit.

That didn’t really fix it, so I’m wondering if there’s a way to check that the settings are set up correctly. This is a website with really a lot of images. I guess there’s just too little memory available for this site.

The first steps I’d try is if single thumbs are generated correctly on a page with a single image. Also make sure that the correct thumbs are generated, not only copies of the original image.

I followed your suggestion and created a new template that only renders one (cropped and compressed) image.

<!--one image template -->
<?php $imageFile= $page->files()->first(); ?>

<img height="800px" width="auto" src="<?= esc($imageFile->crop(2560, 1440, 50)->url(), 'attr') ?>">

Once the image has been uploaded, the thumbnail in the backend also needs to be reloaded for it to be visible.

when I first open the page the image also doesn’t load. But after reloading, the image is cropped and compressed perfectly.
Note: When I remove the crop() method I get the same error.

Can you reproduce the issue with a fresh Starterkit on the same server?

The starter kit works perfectly. There is no need to refresh for new uploaded images.

Guess what. I found the error. It was caused by a plugin’s index.php

It was the first empty line …
I removed it and everything works perfectly :full_moon_face:

Was it your own plugin or a third party’s? If not your own, maybe create a bug report.

was my own private plugin.
Thanks a lot for helping me finding the error!