kirby-blurry-placeholder icon indicating copy to clipboard operation
kirby-blurry-placeholder copied to clipboard

Handling static assets

Open tobimori opened this issue 3 years ago • 2 comments

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
    {
		[..]
	}

tobimori avatar Feb 23 '22 01:02 tobimori

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

(new \Kirby\Image\Image('assets/images/logo.png))->placeholderUri();

johannschopplich avatar Feb 23 '22 07:02 johannschopplich

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"

tobimori avatar Feb 24 '22 04:02 tobimori

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!

johannschopplich avatar Jan 06 '23 07:01 johannschopplich