chore: make album thumbnail blurry

This commit is contained in:
Phan An 2020-06-12 17:05:18 +02:00
parent 6977cc4986
commit dcf6970355
6 changed files with 14 additions and 7 deletions

View file

@ -21,8 +21,8 @@ class AlbumThumbnailController extends Controller
/**
* Get an album's thumbnail
*
* Get an album's thumbnail (a 48px-wide version of the album's cover). Returns the full URL to the thumbnail,
* or NULL if the album has no cover.
* Get an album's thumbnail (a 48px-wide blurry version of the album's cover).
* Returns the full URL to the thumbnail or NULL if the album has no cover.
*
* @response ["thumbnailUrl", "https://localhost/public/img/covers/a146d01afb742b01f28ab8b556f9a75d_thumbnail.jpg"]
* @return JsonResponse

View file

@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property bool $is_unknown
*
* @method static self firstOrCreate(array $where, array $params = [])
* @method static self|null find(int $id)
*/
class Album extends Model
{

View file

@ -19,7 +19,7 @@ class ImageWriter
public function writeFromBinaryData(string $destination, string $data, array $config = []): void
{
$this->imageManager
$img = $this->imageManager
->make($data)
->resize(
$config['max_width'] ?? self::DEFAULT_MAX_WIDTH,
@ -27,7 +27,12 @@ class ImageWriter
$constraint->upsize();
$constraint->aspectRatio();
}
)
->save($destination, $config['quality'] ?? self::DEFAULT_QUALITY);
);
if (isset($config['blur'])) {
$img->blur($config['blur']);
}
$img->save($destination, $config['quality'] ?? self::DEFAULT_QUALITY);
}
}

View file

@ -110,7 +110,7 @@ class MediaMetadataService
$this->imageWriter->writeFromBinaryData(
$thumbnailPath,
file_get_contents($album->cover_path),
['max_width' => 48]
['max_width' => 48, 'blur' => 10]
);
}

@ -1 +1 @@
Subproject commit 428ab7414fa77533b1f1d6fadee23999e13b5a4b
Subproject commit 194d254110d4f185e83300a3d4e9b3cefbf09dbf

View file

@ -45,6 +45,7 @@ class MediaMetadataServiceTest extends TestCase
public function testWriteArtistImage(): void
{
/** @var Artist $artist */
$artist = factory(Artist::class)->create();
$imageContent = 'dummy';
$imagePath = '/koel/public/images/artist/foo.jpg';