SkinCache
, (*1)
Cache Minecraft skins/icons and serve them locally., (*2)
Dependencies
All dependencies are handled by composer. Installing cURL is recommended and will be used if installed but it isn't required., (*3)
Usage
There is a class PublicUHC\SkinCache\SimpleSkinFetcher
that uses some default classes and can be used like this:, (*4)
$fetcher = new SimpleSkinFetcher('https://minotar.net', 10, './cache', 3600);
To change the classes used or for better tweaking use the class PublicUHC\SkinCache\SkinFetcher
., (*5)
It requires a Downloader, a Formatter, a PoolInterface and a ErrorImagePainter. It also requires a 'ttl', either null to store forever, an integer as the number of seconds until expiry or a DateTime for when the fetched skins should expire., (*6)
Downloader
There is only 1 implementation of downloader available:, (*7)
PublicUHC\SkinCache\Downloaders\MinotarLikeDownloader
, (*8)
It fetches from a base URL supplied in a minotar-like fashion., (*9)
Skins are fetched from <base_url>/skin/<username>
, (*10)
Helms are fetched from <base_url>/helm/<username>/<size>.png
, (*11)
Heads are fetched from <base_url>/avatar/<username>/<size>.png
, (*12)
It expects a GuzzleHttp\Client
object initialized for getting the data with. At minimum a base_url needs to be set., (*13)
$client = new GuzzleHttp\Client(['base_url' => 'https://minotar.net/']);
For more information on the Client object visit the Guzzle project on GitHub, (*14)
It also expects a timeout in seconds for the fetching., (*15)
Example for fetching from minotar.net with a 30 second timeout:, (*16)
$downloader = new MinotarLikeDownloader(new Client(['base_url' => 'https://minotar.net/']), 30);
NOTE: Only the raw images are cached, any formatting is applied to the raw images, (*17)
There are 3 implementations of the formatter available:, (*18)
PublicUHC\SkinCache\Formatters\HttpResponseFormatter
, (*19)
It formats the images in a Symfony HttpResponse format from the Symfony Http Foundation project, (*20)
PublicUHC\SkinCache\Formatters\RawImageFormatter
, (*21)
Returns the image as the raw image string, (*22)
PublicUHC\SkinCache\Formatters\GreyscaleFormatter
, (*23)
Returns the image as a greyscale version of itself, (*24)
Formatters can be chained to make multiple formatting passes:, (*25)
$formatter = (new GreyscaleFormatter())->then(new HttpResponseFormatter());
This will first make it greyscale and then make it a Http Foundation response., (*26)
PoolInterface
Expects a PoolInterface from the Stash PHP Project., (*27)
Example - throws away objects, no cache:, (*28)
$pool = new Pool(new BlackHole());
Example - using the default Ephemeral driver:, (*29)
$pool = new Pool();
ErrorImagePainter
There is only 1 implementation of the error image painter available:, (*30)
PublicUHC\SkinCache\Painters\TransparentImagePainter
, (*31)
It will return a transparent image of the same dimensions for error images, (*32)
Full Example
The following example uses the MinotarLikeDownloader to fetch skins from the official minotar site, formats them in Http Foundation Response style and uses the default Ephemeral cache driver and then fetches the helm for the 'ghowden' account 16x16, (*33)
$downloader = new MinotarLikeDownloader(new Client(['base_url'=>'https://minotar.net/']));
$fetcher = new SkinFetcher($downloader, new HttpResponseFormatter(), new Pool(), new TransparentImagePainter());
$fetcher->fetchHelm('ghowden', 16);