quick custom plugin
you could also create your own Asset
class (extending the kirby one) and use it to return a base64 encoded svg image as url.
I’ve hacked something together for you:
/site/plugins/textpreview/index.php:
<?php
namespace bruno\textpreview;
use Kirby\Cms\Asset;
use Kirby\Cms\App as Kirby;
class VirtualAsset extends Asset {
protected $text = '';
public function __construct(string $text) {
$this->text = $text;
}
public function url(): string {
$text = $this->text;
return 'data:image/svg+xml;base64,'
. base64_encode(
"<svg xmlns='http://www.w3.org/2000/svg'>" .
"<text fill=\"white\" x=\"50%\" y=\"50%\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"24\">$text</text>" .
"</svg>");
}
}
Kirby::plugin('bruno/textpreview-pagemethod', [
'pageMethods' => [
'textPreview' => function($text) {
return new VirtualAsset($text);
}
]
]);
then use it like this:
sections:
mypages:
type: pages
image: page.textPreview(page.children.count)
Looks like this:
Now make it pretty