@@ -6,8 +6,12 @@ const IDENTITY_COLORS: { [key: string]: string } = {
66 discord : "#5866f2" ,
77} ;
88
9- export async function getIdentityImage ( namespace : string , handle : string ) {
10- console . log ( `Rending ${ namespace } image` ) ;
9+ export async function getIdentityImage (
10+ namespace : string ,
11+ handle : string ,
12+ proxy ?: boolean
13+ ) {
14+ console . log ( `Rendering ${ namespace } image` ) ;
1115
1216 // setup
1317 canvas . registerFont ( __dirname . concat ( "/fonts/SF-Pro.ttf" ) , {
@@ -29,7 +33,13 @@ export async function getIdentityImage(namespace: string, handle: string) {
2933 nameCtx . textAlign = "center" ;
3034 nameCtx . textBaseline = "middle" ;
3135
32- const nameText = formatName ( namespace , handle ) ;
36+ let nameText = decodeURIComponent ( formatName ( namespace , handle ) ) ;
37+ let topRightText : string | undefined ;
38+ if ( namespace === "discord" ) {
39+ const temp = nameText . split ( "#" ) ;
40+ nameText = temp . slice ( 0 , - 1 ) . join ( ) ;
41+ topRightText = temp . pop ( ) ;
42+ }
3343 nameCtx . fillText ( nameText , WIDTH * 0.5 , HEIGHT * 0.5 ) ;
3444 nameCtx . textAlign = "left" ;
3545
@@ -46,26 +56,28 @@ export async function getIdentityImage(namespace: string, handle: string) {
4656 HEIGHT * 0.18
4757 ) ;
4858
49- const bottomLeftCtx = imageCanvas . getContext ( "2d" ) ;
50- bottomLeftCtx . textAlign = "left" ;
51- let bottomLeft = PADDING * 1.5 ;
59+ if ( ! proxy ) {
60+ const bottomLeftCtx = imageCanvas . getContext ( "2d" ) ;
61+ bottomLeftCtx . textAlign = "left" ;
62+ let bottomLeft = PADDING * 1.5 ;
5263
53- bottomLeftCtx . font = `${ 0.055 * WIDTH } px SFPro` ;
54- bottomLeftCtx . fillStyle = "white" ;
55- bottomLeftCtx . drawImage (
56- await canvas . loadImage ( __dirname . concat ( "/assets/infinity.png" ) ) ,
57- PADDING ,
58- HEIGHT - bottomLeft - 0.08 * WIDTH ,
59- 0.15 * WIDTH ,
60- 0.15 * WIDTH
61- ) ;
62- bottomLeft += 0.075 * WIDTH ;
64+ bottomLeftCtx . font = `${ 0.055 * WIDTH } px SFPro` ;
65+ bottomLeftCtx . fillStyle = "white" ;
66+ bottomLeftCtx . drawImage (
67+ await canvas . loadImage ( __dirname . concat ( "/assets/infinity.png" ) ) ,
68+ PADDING ,
69+ HEIGHT - bottomLeft - 0.08 * WIDTH ,
70+ 0.15 * WIDTH ,
71+ 0.15 * WIDTH
72+ ) ;
73+ bottomLeft += 0.075 * WIDTH ;
74+ }
6375
64- const topLextCtx = imageCanvas . getContext ( "2d" ) ;
76+ const topLeftCtx = imageCanvas . getContext ( "2d" ) ;
6577 let topLeft = PADDING ;
6678 if ( IDENTITIES . includes ( namespace ) ) {
6779 if ( namespace === "twitter" ) {
68- topLextCtx . drawImage (
80+ topLeftCtx . drawImage (
6981 await canvas . loadImage (
7082 __dirname . concat ( "/assets/twitter-white-logo.png" )
7183 ) ,
@@ -75,7 +87,7 @@ export async function getIdentityImage(namespace: string, handle: string) {
7587 0.15 * HEIGHT
7688 ) ;
7789 } else if ( namespace === "discord" ) {
78- topLextCtx . drawImage (
90+ topLeftCtx . drawImage (
7991 await canvas . loadImage ( __dirname . concat ( "/assets/discord-logo.png" ) ) ,
8092 topLeft ,
8193 PADDING ,
@@ -86,6 +98,14 @@ export async function getIdentityImage(namespace: string, handle: string) {
8698 topLeft += 0.11 * WIDTH ;
8799 }
88100
101+ if ( topRightText ) {
102+ const topRightCtx = imageCanvas . getContext ( "2d" ) ;
103+ topRightCtx . font = `${ 0.08 * WIDTH } px SFPro` ;
104+ topRightCtx . fillStyle = "white" ;
105+ topRightCtx . textAlign = "right" ;
106+ topRightCtx . fillText ( "#" + topRightText , WIDTH * 0.95 , HEIGHT * 0.1 ) ;
107+ }
108+
89109 const buffer = imageCanvas . toBuffer ( "image/png" ) ;
90110 return buffer ;
91111}
0 commit comments