blessing-skin-server/app/Listeners/CacheAvatarPreview.php

27 lines
593 B
PHP
Raw Normal View History

<?php
namespace App\Listeners;
use Cache;
use Storage;
use Minecraft;
use App\Events\GetAvatarPreview;
class CacheAvatarPreview
{
public function handle(GetAvatarPreview $event)
{
$texture = $event->texture;
$size = $event->size;
$key = "avatar-{$texture->tid}-$size";
$content = Cache::rememberForever($key, function () use ($texture, $size) {
$res = Storage::disk('textures')->read($texture->hash);
2019-04-19 19:36:36 +08:00
return png(Minecraft::generateAvatarFromSkin($res, $size));
});
return response()->png($content);
}
}