Generating thumbs on upload

Is it possible to set up Kirby 3 in a way that it generates thumbs in predefined sizes on upload right away?

Something like:

'file.create:after' => function($file) {
    $widths = [350, 750, 1250];

    if($file->isResizable()) {
        foreach($widths as $width) {
            try {
                $resizedImage = $file->resize($width)->save();
            catch (Exception $e) {
                throw new Exception($e->getMessage());

It might end up taking a while on big uploads though.

1 Like

Cool, I will try this, thanks @sylvainjule!

It might end up taking a while on big uploads though.

That’s why I want to generate thumbs directly :slight_smile:

Hahaha, client education through longer upload times. I like that!


Well, you know :roll_eyes:

@bastianallgeier: Seriously, if the thumb generation is combined with the upload, users understand that they are adding weight to the page: the original image, and 3 or more thumb variations for source sets or different spots of the site.

If the thumbs are generated on page load, the user thinks the site itself or the server is slow (which is or course true in that moment).

But besides the learning effect, the users of the panel are more likely to wait for the images than visitors of the site who might just leave.