-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mebtte
committed
Mar 7, 2024
1 parent
a8d70d4
commit 3408f51
Showing
12 changed files
with
182 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
apps/pwa/src/pages/player/pages/my_music/create_music_dialog/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IMAGE_MAX_SIZE } from '#/constants'; | ||
import loadImage from '@/utils/load_image'; | ||
|
||
export async function base64ToCover(base64: string) { | ||
const imgNode = await loadImage(base64); | ||
|
||
const size = Math.min( | ||
IMAGE_MAX_SIZE, | ||
imgNode.naturalWidth, | ||
imgNode.naturalHeight, | ||
); | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = size; | ||
canvas.height = size; | ||
const context = canvas.getContext('2d')!; | ||
|
||
context.drawImage( | ||
imgNode, | ||
(size - imgNode.naturalWidth) / 2, | ||
(size - imgNode.naturalHeight) / 2, | ||
imgNode.naturalWidth, | ||
imgNode.naturalHeight, | ||
); | ||
return await new Promise<Blob>((resolve) => | ||
canvas.toBlob((blob) => resolve(blob!), 'image/jpeg', 0.8), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.