# \[V4\] Generate thumbs on image upload

**URL:** <https://forum.getkirby.com/t/v4-generate-thumbs-on-image-upload/30084>\
**Category:** Questions\
**Created:** [November 24, 2023, 9:32am UTC](https://forum.getkirby.com/t/v4-generate-thumbs-on-image-upload/30084 "2023-11-24T09:32:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Cris](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cris/32/14642_2.png) [@Cris](https://forum.getkirby.com/u/Cris)\
**Post date:** [November 25, 2023, 8:30am UTC](https://forum.getkirby.com/t/v4-generate-thumbs-on-image-upload/30084/2 "2023-11-25T08:30:13Z")

</div>

I haven’t tested k4 yet.  
But maybe You could use a hook to trigger the thumb generation after file upload/ replace.  
Something I’d do in a k3 plugin (not tested, just to get the idea):

```php

use Kirby\Cms\App;
use Kirby\Cms\Exception;

Kirby::plugin('k-community/auto-thumb-or-whatever', [
	'hooks' => [
		'file.create:after'	=> fn($file) => $file->autoThumb(),
		'file.replace:after' => fn($newFile, $oldFile) => $newFile->autoThumb()
	],
	
	'fileMethods' => [
		'autoThumb' => function() {
			$kirby = App::instance();

			if($this->isResizable()) {
				try {
					
					$kirby->thumb($this->root(), $this->root(), 'myPreset');
					
					// Immediately generate a file in the media folder. 
					$this->publish();
					 
				} catch (Exception $e) {
					throw new Exception($e->getMessage());
				}
			}
		}
	]
]);

```

---

_[View the full topic](https://forum.getkirby.com/t/v4-generate-thumbs-on-image-upload/30084)._
