2 Commits

Author SHA1 Message Date
GitBluub
46d427363f one more radioart for later 2024-01-12 12:34:40 +01:00
GitBluub
0b8b58e915 feat: overlay artist image and background for cover 2023-11-16 04:52:38 +01:00
10 changed files with 836 additions and 10151 deletions

BIN
back/artist.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

BIN
back/background_cover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
back/icon_dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

10950
back/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -21,6 +21,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@jimp/plugin-circle": "^0.22.10",
"@nestjs-modules/mailer": "^1.9.1",
"@nestjs/common": "^10.1.0",
"@nestjs/config": "^3.0.0",
@@ -36,9 +37,9 @@
"@types/passport": "^1.0.12",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"json-logger-service": "^9.0.1",
"class-validator": "^0.14.0",
"jimp": "^0.22.10",
"json-logger-service": "^9.0.1",
"node-fetch": "^2.6.12",
"nodemailer": "^6.9.5",
"passport-google-oauth20": "^2.0.0",

BIN
back/radioart.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
back/radioart2.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
back/radioart3.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
back/radioart4.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -37,6 +37,7 @@ import { Song as _Song } from 'src/_gen/prisma-class/song';
import { SongHistory } from 'src/_gen/prisma-class/song_history';
import { IncludeMap, mapInclude } from 'src/utils/include';
import { Public } from 'src/auth/public';
import Jimp from 'jimp';
class SongHistoryResult {
@ApiProperty()
@@ -45,6 +46,9 @@ class SongHistoryResult {
history: SongHistory[];
}
const BACKGROUND_COVER = 'radioart3.jpeg';
const ICON = 'icon_dark.png';
@Controller('song')
@ApiTags('song')
@UseGuards(JwtAuthGuard)
@@ -85,6 +89,21 @@ export class SongController {
}
}
async gen_illustration(song: Song) {
const img = await Jimp.read(BACKGROUND_COVER);
// @ts-ignore
const artist_img = await Jimp.read(`/assets/artists/${song.artist.name}/illustration.png`);
const logo = await Jimp.read(ICON);
img.cover(600, 600);
artist_img.cover(400, 400);
logo.cover(70, 70);
artist_img.circle();
img.composite(artist_img, 100, 100);
img.composite(logo, 10, 10);
return img;
}
@Get(':id/illustration')
@ApiOperation({
description: 'Streams the illustration of the requested song',
@@ -93,13 +112,16 @@ export class SongController {
@ApiOkResponse({ description: 'Returns the illustration succesfully' })
@Public()
async getIllustration(@Param('id', ParseIntPipe) id: number) {
const song = await this.songService.song({ id });
const song = await this.songService.song({ id }, { artist: true } );
if (!song) throw new NotFoundException('Song not found');
//await this.gen_illustration(song);
if (song.illustrationPath === null) throw new NotFoundException();
if (!existsSync(song.illustrationPath))
throw new NotFoundException('Illustration not found');
if (!existsSync(song.illustrationPath)) {
let img = await this.gen_illustration(song);
img.write(song.illustrationPath);
}
try {
const file = createReadStream(song.illustrationPath);
return new StreamableFile(file);