Constant broken images

So I have problems om multiple websites with images not working.

The image just shows up as a broken link, then if I do a do a hard reload of the page it works again? But if I reload normally the image is still broken.

If I go straight to the image source, it first generates a 404. Then on hard reload it works again?

The images isnt newly uploaded, they have often been there for weeks/months.

Anyone knows the problem? Im running Kirby 4.3 with PHP 8.2.21 on LiteSpeed.
Since its random its so hard to catch the bug.

My config looks like this when it comes to images (but the problem is not connected to srcset):


        'thumbs' => [
            'format' => 'webp',
            'srcsets' => [
                'default' => [
                    '500w'  => ['width' => 500],
                    '900w'  => ['width' => 900],
                    '1200w' => ['width' => 1200],
                    '1800w' => ['width' => 1800],
                    '2200w' => ['width' => 2500],
                ],
                'showcase' => [
                    '500w'  => ['width' => 500],
                    '900w'  => ['width' => 900],
                    '1200w' => ['width' => 1200],
                ],
            ],
        ],

Has anything changed on the server with the PHP config maybe? Try changing the image driver over to Image Magick (or to GD if you already are using that). Its a wild guess but feels like a broken install of one of them after a server software update.

Thanks for the reply. I guess that GD is default? Tried adding IM in the config-file but still the same issue.

No changes in the server. On one of the sites Ive changed from 8.1 to 8.2 in PHP but nothing else…

 // Images
        'thumbs' => [
            'format' => 'webp',
            'driver' => 'im',
            'srcsets' => [
                'default' => [
                    '500w'  => ['width' => 500],
                    '900w'  => ['width' => 900],
                    '1200w' => ['width' => 1200],
                    '1800w' => ['width' => 1800],
                    '2200w' => ['width' => 2500],
                ],
                'showcase' => [
                    '500w'  => ['width' => 500],
                    '900w'  => ['width' => 900],
                    '1200w' => ['width' => 1200],
                ],
            ],
        ],

Trying the above config now and see if it makes any difference

I think there is some information missing in your issue description. You describe a symptom, but not what you did before it came up. If the images are there for weeks or even months, I assume that the sites were not created using Kirby 4.3, but that you did an update at some point. Is that the time when the issue started? Or is it unrelated?

What about your setup, are the sites behind a load balancer?

Still feels shaky, but was missing a row in .htaccess

RewriteCond %{REQUEST_URI} !^/media

That seem to make stuff work in production but locally nothings working connected to the images. So I added some logic in the config.php so it runs locally aswell.

    $is_dev = false;
    if (strpos($_SERVER['HTTP_HOST'], '.test') !== false) {
        $is_dev = true;
    }

    // Images
    $thumbs = [
        'srcsets' => [
            'default' => [
                '500w'  => ['width' => 500],
                '900w'  => ['width' => 900],
                '1200w' => ['width' => 1200],
                '1800w' => ['width' => 1800],
                '2200w' => ['width' => 2500],
            ],
            'showcase' => [
                '500w'  => ['width' => 500],
                '900w'  => ['width' => 900],
                '1200w' => ['width' => 1200],
            ],
        ],
    ];
    
    if (!$is_dev) {
        $thumbs['format'] = 'webp';
        $thumbs['driver'] = 'im';
        $thumbs['threads'] = 2;
    }
    
    return [
        // Debug
        'debug' => $is_dev,
    
        // Images
        'thumbs' => $thumbs,

Clearly something with the image driver is creating issues locally for me. Im both using MAMP for some sites and Docker for some. Same issues…

The error that was happening was that if I removed the media folder content and refreshed the page all images wore find, both front-end and in the panel. But if I made a refresh again, all links broke. Then if I made a hard refresh in Chrome, they worked again.

Also… locally there been issues with broken links even if I’ve not used format, driver and threads in the config. Loads of work files not getting executed and made into images. But read somewhere that images then to be shaky locally when using Kirby

Never had that problem myself locally, so don’t know. The job files get converted to thumbs when they are required via url, not as long as they are not needed. Doesn’t explain why files are found and then not found…

1 Like

What server are you using locally? If its valet or herd, then the rules in the .htaccess file will not be used at all since it Nginx not Apache.

Its Apache since I´m running it thru MAMP

Managed to get an error message now. Something is clearly not working with imagemagick…

Exception thrown with message "The imagemagick convert command could not be executed: 'convert' -limit thread '2' '/Applications/MAMP/htdocs/balowie/media/pages/tidigare-projekt/16317fd32e-1713170959/cawatayoga-mobil-yoga-mockup-500x.webp' -auto-orient -thumbnail '500x281!' -quality '90' '/Applications/MAMP/htdocs/balowie/media/pages/tidigare-projekt/16317fd32e-1713170959/cawatayoga-mobil-yoga-mockup-500x.webp'"

Stacktrace:
#10 Exception in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Image/Darkroom/ImageMagick.php:153
#9 Kirby\Image\Darkroom\ImageMagick:process in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/config/components.php:343
#8 Kirby\Cms\Core:{closure} in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Cms/App.php:1614
#7 Kirby\Cms\App:thumb in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Cms/Media.php:136
#6 Kirby\Cms\Media:thumb in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Cms/Media.php:61
#5 Kirby\Cms\Media:link in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/config/routes.php:89
#4 Kirby\Http\Route:{closure} in [internal]:0
#3 Closure:call in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Http/Router.php:120
#2 Kirby\Http\Router:call in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Cms/App.php:338
#1 Kirby\Cms\App:call in /Applications/MAMP/htdocs/balowie/vendor/getkirby/cms/src/Cms/App.php:1191
#0 Kirby\Cms\App:render in /Applications/MAMP/htdocs/balowie/index.php:9

Also the broken links in panel was caused by using cover. When removing it works, but looks shit. But same there, If i remove imagemagick as the driver the cover works… Guess I will stick to the standard image driver

image:
    query: page.seoImage.toFile
    cover: true
    ratio: 16/9