This extension provides an avatar
property to display the default profile photo from the page. The resulting photo is expected to be rectangular and can be dynamically resized using the avatar()
method call. However, this is entirely up to the services that provide this feature. This extension is only responsible for providing the width and height of the image and displaying the default profile photo.
Usage
<!-- Default avatar image URL -->
<img alt="" src="<?= eat($page->avatar); ?>">
<!-- Custom avatar image URL, expected to display an image URL where the image width is 80 pixels and the image height is 80 pixels -->
<img alt="" src="<?= eat($page->avatar(80)); ?>">
Third-party services can be added this way to change the output of the default profile photo:
Hook::set('page.avatar', function (?string $avatar, array $lot = []) {
// Prioritize local avatar URL
if ($avatar) {
return $avatar;
}
// Convert email address from the page to a unique hash
$hash = md5($this->email);
// Get the first parameter which indicates the scale size of the profile photo (default scale size is `80`)
$size = array_shift($lot) ?: 80;
// Return the profile photo URL
return 'https://example.com/service/photo/' . $hash . '.jpg' . (is_int($size) && $size > 0 ? '?size=' . $size : "");
}, 1);
0 Comments
No comments yet.