-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
34 lines (32 loc) · 2.06 KB
/
index.php
File metadata and controls
34 lines (32 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php namespace x\avatar;
function page__avatar($avatar, array $lot = []) {
if (!$avatar || !\is_string($avatar)) {
$size = \ceil(\array_shift($lot) ?: 80);
return 'data:image/svg+xml;base64,' . \base64_encode('<svg height="' . $size . '" version="1.1" viewBox="0 0 200 200" width="' . $size . '" xmlns="http://www.w3.org/2000/svg"><path d="M0,0H200V200H0Z" fill="#' . \substr(\md5($this['author'] ?? ""), 0, 6) . '"></path><path d="M121.178 125.08C135.217 117.463 144.75 102.595 144.75 85.5 144.75 60.647 124.603 40.5 99.75 40.5 74.896 40.5 54.75 60.647 54.75 85.5 54.75 102.674 64.372 117.596 78.518 125.181 50.169 135.119 28.984 164.207 26 200H173.902C171.006 164.082 149.678 134.917 121.178 125.08Z" fill="#fff"></path></svg>');
}
\extract(\lot(), \EXTR_SKIP);
if (!isset($state->x->image) || !$lot) {
return $avatar;
}
// Ignore external avatar(s)
if (false !== \strpos($avatar, '://') || 0 === \strpos($avatar, '//') || 0 !== \strpos($avatar, '/')) {
return $avatar;
}
// Process local avatar(s)
$w = \ceil(\array_shift($lot) ?: 80);
$h = \ceil(\array_shift($lot) ?: $w);
$q = \ceil(\array_shift($lot) ?: -1);
$x = \strtolower(\pathinfo($avatar, \PATHINFO_EXTENSION) ?: 'jpg');
$path = \To::path(\long($avatar));
$store = \LOT . \D . 'image' . \D . 't' . \D . 'avatar' . \D . $w . ($h !== $w ? \D . $h : "") . \D . \hash('xxh3', $avatar . '%' . $q) . '.' . $x;
if (false !== \strpos(',' . \x\image\x() . ',', ',' . $x . ',')) {
$blob = new \Image(\is_file($path) ? $path : $avatar);
// `$page->avatar($width, $height, $quality)`
$blob->crop($w, $h)->blob($store, $q); // Generate avatar cache
$avatar = \To::link($store); // Return the avatar cache link
// Convert direct avatar link from folder `.\lot\image` to its proxy image link
$avatar = \substr_replace($avatar, \long('/' . \trim($state->x->image->route ?? 'image', '/') . '/'), 0, \strlen(\long('/lot/image/')));
}
return $avatar;
}
\Hook::set('page.avatar', __NAMESPACE__ . "\\page__avatar", 2);