Where is the place to change thumb defaults?

Hello,

When I add an image to a page, a thumbnail file is created at “/thumbs/page” folder. And the file’s dimensions are 75,75px. But I want to change these sizes. Actually I don’t want to crop images. Want only change the width and calculate height automaticaly. Generally and specific for a page.

Is it possible to do that?

Thank you

What is your use case? The 75x75 thumb is only generated for use in the panel. In the frontend, you can create whatever sizes you need.

I want to create thumbnails automatically when I add image in the panel. Then I can use them in the front-end. If I create thumbs in the front-end, then the generation could happen every time when the user visit the page? I really don’t get it.

No, the thumbnail is only created if it does not exist yet, not every time the page is reloaded. You can of course use a hook to automatically create the thumbs on file upload/replace: https://getkirby.com/docs/developer-guide/advanced/hooks

1 Like

I will definitely look at it and return here with the result after some experiments.

However, I’m not sure you really need to create these thumbnails in advance. Anyway, here is an example hook:

kirby()->hook('panel.file.upload', function($file) {
    // your hook code
    $maxDimension = 1024;
    if ($file->width() > $maxDimension or $file->height() > $maxDimension) {
       // give a 1024x1024 image (for testing purposes) 
       $file->resize($maxDimension,$maxDimension);
     } 		
    });

If you need several sizes, you would have to adapt this accordingly.

1 Like

Perfect. Thank you so much!

kirby()->hook(['panel.file.upload', 'panel.file.replace'], function($file) {
		$IDsToProceed = ["home", "test"];
		if (in_array($file->page()->id(), $IDsToProceed)) {
	    	thumb($file, array('width' => 300));
			// debug
	    	$path = kirby()->roots()->content();      
	    	file_put_contents( $path . '/test.txt', print_r($file->page()->id(), true) );
		}
});