4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 21:26:37 +00:00
AzuraCast/src/Assets/AlbumArtCustomAsset.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2021-07-30 06:20:14 +00:00
<?php
declare(strict_types=1);
namespace App\Assets;
use Intervention\Image\Constraint;
use Intervention\Image\Image;
final class AlbumArtCustomAsset extends AbstractMultiPatternCustomAsset
2021-07-30 06:20:14 +00:00
{
protected function getPatterns(): array
2021-07-30 06:20:14 +00:00
{
return [
'default' => 'album_art%s.jpg',
'image/png' => 'album_art%s.png',
'image/webp' => 'album_art%s.webp',
];
2021-07-30 06:20:14 +00:00
}
protected function getDefaultUrl(): string
{
return $this->environment->getAssetUrl() . '/img/generic_song.jpg';
2021-07-30 06:20:14 +00:00
}
public function upload(Image $image): void
{
$newImage = clone $image;
$newImage->resize(1500, 1500, function (Constraint $constraint) {
$constraint->upsize();
});
$this->delete();
$patterns = $this->getPatterns();
$mimeType = $newImage->mime();
$pattern = $patterns[$mimeType] ?? $patterns['default'];
2023-01-03 22:55:49 +00:00
$destPath = $this->getPathForPattern($pattern);
$this->ensureDirectoryExists(dirname($destPath));
2023-01-03 22:55:49 +00:00
$newImage->save($destPath, 90);
2021-07-30 06:20:14 +00:00
}
}