Update broke thumbnail creation

Hi there. I’m using Kirby to display a large amount of images in a gallery (similar to Flickr), but it seems something broke with the 2.3.1 update, and I’m not shure where exactly the problem is. Basically, I want to serve compressed and resized thumbnails for as many screen resolutions as possible. The gallery plugin I’m using can automatically load the best available thumbnail, as long as they all have a certain suffix, so up until now I’ve just pre-generated the thumbnails with a hook like this:

kirby()->hook('panel.file.upload', function($file) {
    $imageconvert1 = new thumb($file, array('width' => 320, 'height' => 320, 'filename' => '{safeName}-320.{extension}'));
    $imageconvert2 = new thumb($file, array('width' => 640, 'height' => 640, 'filename' => '{safeName}-640.{extension}'));
    $imageconvert3 = new thumb($file, array('width' => 800, 'height' => 800, 'filename' => '{safeName}-800.{extension}'));
    $imageconvert4 = new thumb($file, array('width' => 1024, 'height' => 1024, 'filename' => '{safeName}-1024.{extension}'));
    $imageconvert5 = new thumb($file, array('width' => 1600, 'height' => 1600, 'filename' => '{safeName}-1600.{extension}'));
    $imageconvert6 = new thumb($file, array('width' => 1920, 'height' => 1920, 'filename' => '{safeName}-1920.{extension}'));
    $imageconvert7 = new thumb($file, array('width' => 2048, 'height' => 2048, 'filename' => '{safeName}-2048.{extension}'));
});

And then frankensteined the URL together like this (I’m shure there’s a better/cleaner way to do this, but my PHP knowledge is limited):

<img src="<?php echo kirby()->urls()->content() ?>/<?php echo $screenshot->page()->diruri() ?>/thumbs/<?php echo $screenshot->name()?>-640.<?php echo $screenshot->extension()?>" itemprop="thumbnail" alt="<?php echo $screenshot->title() ?>">

This used to work fine, but as mentioned, the 2.3.1 update broke the thumbnail creation, uploading an image doesn’t generate anything anymore. I’ve tried to remove the “new” before “thumb”, which seems to fix the problem, until I upload a second picture and all previously generated thumbnails get deleted (another person seems to have the same problem).

I’m not shure if this is a bug or if I need to update my code to work with the new API, either way I have no clue how to fix this. What can I do? Is there another solution I can try? I’ve read something on GitHub about a versions feature, but it doesn’t seem like it’s implemented yet. Any help would be greatly appreciated.

Instead of manually concatenating the URL, you can use the thumb method there. It will only generate the thumb if it doesn’t already exist:

<img src="<?php echo $screenshot->resize(640, 640)->url() ?>" itemprop="thumbnail" alt="<?php echo $screenshot->title() ?>">

Regarding the issue that all thumbs get deleted once you upload an image: That’s really strange, I don’t know where that comes from.

1 Like

Thanks for your answer. Yeah, it’s really strange, especially since everything worked fine up to 2.2.3. According to the changelog, the panel.file.upload hook was fixed in 2.3.0, maybe something went wrong there?

As for using the new thumb method: This is a great idea, but I’m not shure if it will work for my case. Since the images need to have a custom suffix, I have to change the filename pattern, which isn’t possible with the new thumb method? I also can’t do this in my config, since the suffix I’m looking for can be either the {width} or {height}, depending on the aspect ratio of the image. But I guess using the old method instead should still work fine?

<img src="<?php echo thumb($screenshot->image(), array('width' => 640, 'height' => 640, 'filename' => '{safeName}-640.{extension}'))->url() ?>" itemprop="thumbnail" alt="<?php echo $screenshot->title() ?>">

Yes, that’s totally fine. :slight_smile:

Concerning the “all thumbs get deleted” issue: I have noted this as an issue on GitHub and we will look into this.

2 Likes

I’ve found the cause of this problem, see the github issue for more details.

1 Like

I’m sorry for bumping this topic, but are there any updates on the thumbnail issue? It’s been over a month, v2.3.2 didn’t fix it and it’s still a quite severe problem for me, since it broke my whole site and rendered it unusable.

Even worse, I’m out of options for “fixing” this issue. I can’t downgrade back to v2.2.3, since I’m relying on plugins that require v2.3 and up. I can’t rewrite my site, which would either be close to impossible with my limited knowledge or a lot of work. Same goes for generating and uploading 7+ thumbnails for each picture. So I’m currently stuck with a broken website, which is more than frustrating, especially if a (possible) fix is planned for v2.4 at best. Does anyone else have any idea what I could try, until this gets fixed? Can I downgrade only the panel to v2.2.3, and keep the core on v2.3.2? Or am I stuck with twiddling my thumbs for the next months?

Which plugins are you using that require 2.3? The only thing you need to do with those (99% of the time) is to do the registration manually. In the main plugin file (the name of the folder), there should be one or more lines at the beginning that register parts of the plugin as a field, a tag, a template or any other possible things to register.

What I’m suggesting is in no way a long-term solution and I hope the thumb issue is fixed soon. I’m merely suggesting a way for you to try reverting to 2.2.3 without getting stuck by plugins.

Mainly oEmbed 2.0. Still, as you’ve mentioned, downgrading is no long-term solution, and definitely not secure, so I wouldn’t be happy with that “fix”. And modifying the plugin probably isn’t something I’m capable of. I could try to roll the panel files samvantoever mentioned on GitHub back to Mar 20, 2016, but I have no idea if that would help at all. It’s kinda ironic that this issue appeared after the “Fix issue with upload hook” commit, though…