2019-03-21 12:44:15 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use Cache;
|
|
|
|
use Storage;
|
2019-08-08 18:00:11 +08:00
|
|
|
use App\Services\Minecraft;
|
2019-03-21 12:44:15 +08:00
|
|
|
|
|
|
|
class CacheSkinPreview
|
|
|
|
{
|
2019-08-31 09:20:11 +08:00
|
|
|
public function handle($event)
|
2019-03-21 12:44:15 +08:00
|
|
|
{
|
|
|
|
$texture = $event->texture;
|
|
|
|
$size = $event->size;
|
|
|
|
$key = "preview-{$texture->tid}-{$size}";
|
|
|
|
|
|
|
|
$content = Cache::rememberForever($key, function () use ($texture, $size) {
|
|
|
|
$res = Storage::disk('textures')->read($texture->hash);
|
|
|
|
|
|
|
|
if ($texture->type == 'cape') {
|
|
|
|
$png = Minecraft::generatePreviewFromCape($res, $size * 0.8, $size * 1.125, $size);
|
|
|
|
} else {
|
|
|
|
$png = Minecraft::generatePreviewFromSkin($res, $size, $texture->type == 'alex', 'both', 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return png($png);
|
|
|
|
});
|
|
|
|
|
|
|
|
return response()->png($content, 200, [
|
2019-04-19 19:36:36 +08:00
|
|
|
'Last-Modified' => Storage::disk('textures')->lastModified($texture->hash),
|
2019-03-21 12:44:15 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|