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

26 lines
587 B
PHP
Raw Normal View History

<?php
namespace App\Listeners;
use Cache;
use Storage;
2019-08-08 18:00:11 +08:00
use App\Services\Minecraft;
class CacheAvatarPreview
{
2019-08-31 09:20:11 +08:00
public function handle($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));
});
2019-09-10 19:52:17 +08:00
return response($content, 200, ['Content-Type' => 'image/png']);
}
}