Deleting thumbnails from custom folders


I’m trying kirby out for the first time and I really like it so far.

I’d like to set up custom destinations for the thumbnail-files.
Instead of the ”root->thumbs“ folder, I want them to be stored in the subpages.

This is how I got it working, when I write this into the config.php:

c::set('thumbs.destination', function($thumb) {
  $thumbPath = $thumb->page()->root();
  $thumbFolder = '_thumbnails';
  $thumbSafeName = $thumb->source->safeName();

  $root = $thumbPath .DS . $thumbFolder . DS . $thumb->source->name() . '_' .$thumb->options['width'] . 'x' . $thumb->options['height'] . '.' . $thumb->source->extension();
  $url = $thumb->url();

  return new Obj([
	'root' => $root,
    'url'  => $url

Unfortunately, after deleting an image via the panel,
the thumbnail still remains in the custom folder.
I’d appreciate Your help, since my coding knowledge is very limited.

I first thought, that the panel would not delete any thumbnails. But after a small test, I was surprised to see, that all corresponding thumbnails get deleted. This must be a change of the “new” thumbnail system, because I’m pretty sure, that the first thumbnail system hadn’t had this feature.

Anyway: The removal of the thumbnails is part of the panel, not kirby itself. I had a look in the source code and found, that a file delete calls the removeThumbs() function in the file model. app/src/panel/model/file.php
And there you can see, that the thumbnail folder is “hardcoded” in the way, that the Kirby-roots() method is used to find the thumbnail folder.

So i think, that you approach is not possible with the current implementation of the panel. And there is the obligatory question: Why do you want to have the thumbs at the subpage directory? Or why is it a problem, if the thumb do not get deleted?
Otherwise you have to hack the source code of the panel, which is not recommended, because updates are more difficult and tend to break your stuff.

The idea was to keep all cohesive files grouped in one folder structure.

I also thought, that it could make sense, to load only page-specific
thumbnails, rather than scanning a folder with a huge amount of files
in case of bigger projects…

But I might first have to understand how kirby actually works =)

Many thanks for Your help!

FYI: the thumbs folder is not hardcoded, you can move it around. Putting the thumbs next to the originals in a subfolder or something is another thing… I wouldn’t really know how to set that up, nor would I know why I’ld want to do that…

I don’t think it makes sense to store the thumbs in the page folders. At least not if you use version control. You wouldn’t want to version control thumbs.

I know, that you can change the thumbs folder. I wanted to say, that the path is build by concatenating kirby->roots()->thumbs(), the page path and so on. So it is hardcoded in some sense, because the thumbs.destination callback is not used.

Anyway, as texnixe said, I don’t think, that it makes any sense to mix content and thumbnails in one folder. In my point of view, thumbs are not part of the content.