This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move createBadgeDataUrl() into separate utils file
- Loading branch information
Showing
2 changed files
with
32 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function createBadgeDataUrl (text) { | ||
const canvas = document.createElement('canvas'); | ||
canvas.height = 140; | ||
canvas.width = 140; | ||
|
||
const context = canvas.getContext('2d'); | ||
context.fillStyle = 'red'; | ||
context.beginPath(); | ||
context.ellipse(70, 70, 70, 70, 0, 0, 2 * Math.PI); | ||
context.fill(); | ||
context.textAlign = 'center'; | ||
context.fillStyle = 'white'; | ||
|
||
if (text.length > 2) { | ||
context.font = 'bold 65px "Segoe UI", sans-serif'; | ||
context.fillText('' + text, 70, 95); | ||
} else if (text.length > 1) { | ||
context.font = 'bold 85px "Segoe UI", sans-serif'; | ||
context.fillText('' + text, 70, 100); | ||
} else { | ||
context.font = 'bold 100px "Segoe UI", sans-serif'; | ||
context.fillText('' + text, 70, 105); | ||
} | ||
|
||
return canvas.toDataURL(); | ||
} | ||
|
||
export default { | ||
createBadgeDataUrl | ||
}; |
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