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

35 lines
946 B
PHP
Raw Normal View History

<?php
namespace App\Listeners;
2019-12-14 11:10:37 +08:00
use App\Services\Minecraft;
use Cache;
use Storage;
class CacheSkinPreview
{
2019-08-31 09:20:11 +08:00
public function handle($event)
{
$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);
});
2019-09-10 19:52:17 +08:00
return response($content, 200, [
'Content-Type' => 'image/png',
2019-04-19 19:36:36 +08:00
'Last-Modified' => Storage::disk('textures')->lastModified($texture->hash),
]);
}
}