johannschopplich / kirby-blurry-placeholder

🖼 Blurry image placeholders for better UX
MIT License
65 stars 3 forks source link

Handling static assets #15

Closed tobimori closed 1 year ago

tobimori commented 2 years ago

I just figured out how to use this plugin with static files supplied with your Kirby "theme" and maybe we can find a way to extend the Class with methods and implement this into the plugin?

Use the asset helper to get a Kirby\Filesystem\Asset Object:

$asset = asset('/assets/leaves.png');

Then get the placeholderUri manually:

$placeholderUri = \KirbyExtended\BlurryPlaceholder::uri($elFile);

You will also need to switch the accepted parameter type in classes/KirbyExtended/BlurryPlaceholder to mixed.

    /**
     * Creates a blurry image placeholder
     *
     * @param \Kirby\Cms\File|\Kirby\Filesystem\Asset $file
     * @param float|null $ratio
     * @return string
     * @throws \Kirby\Exception\InvalidArgumentException
     */
    public static function image(mixed  $file, $ratio = null): string
    {
        [..]
    }
johannschopplich commented 2 years ago

I like that. Quick question. Doesn't the following work as well (untested)?

(new \Kirby\Image\Image('assets/images/logo.png))->placeholderUri();
tobimori commented 2 years ago

Nope, it doesn't. It seems like File methods are only applied to Cms File classes, not Filesystem classes.

Block error: "Call to undefined method Kirby\Image\Image::placeholderUri()" in block type: "complex-list"
johannschopplich commented 1 year ago

Since we're all in the PHP 8 game, we were able to add the \Kirby\Filesystem\Asset type without relying on mixed. Fixed in https://github.com/johannschopplich/kirby-blurry-placeholder/commit/184ce5290d9db9749b362d1b04ae571accc258d6 and released in v3.0.1.

Thanks for the input!