felixhaeberle / kirby3-webp

🚀🔥 Kirby 3 CMS plugin for converting JPG, JPEG and PNG into much smaller WEBP – speed up your website!
MIT License
39 stars 7 forks source link

Plugin breaks svg uploads #10

Closed ShallowRed closed 1 year ago

ShallowRed commented 2 years ago

Hi, when using this plugin i cannot upload svg files anymore from the panel, as they trigger the file.create:after hook but can't be converted to webp. (actually they get uploaded but trigger an error message).

I think .svg extension should be detected and ignored. To do so I replaced plugin's index.php with:

<?php

@include_once __DIR__ . '/vendor/autoload.php';
@include_once __DIR__ . '/src/webp.php';

Kirby::plugin('felixhaeberle/kirby3-webp', [
    'hooks' => [
        'file.create:after' => function ($file) {
            if ($this->option('kirby3-webp', false) && $file->extension() !== 'svg') {
                (new WebP\Convert)->generateWebP($file);
            }
        },
        'file.replace:after' => function ($newFile, $oldFile) {
            if ($this->option('kirby3-webp', false) && $file->extension() !== 'svg') {
                (new WebP\Convert)->generateWebP($newFile);
            }
        },
    ],
]);

Thanks for the plugin and cheers !

jasminsallam commented 2 years ago

Hey! I also noticed that issue when uploading WebP files. those should also be detected and ignored.

thanks!

felixhaeberle commented 1 year ago

13 fixes this.