kirby-blurry-placeholder
kirby-blurry-placeholder copied to clipboard
Handling static assets
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
{
[..]
}
I like that. Quick question. Doesn't the following work as well (untested)?
(new \Kirby\Image\Image('assets/images/logo.png))->placeholderUri();
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"
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!