2021-04-28 11:01:25 +00:00
import os
2021-05-28 15:39:39 +00:00
import random
2021-04-28 11:01:25 +00:00
import traceback
import uuid
from PIL import Image , ImageDraw , ImageFont , ImageFilter
2021-05-30 06:06:41 +00:00
assets_path = os . path . abspath ( ' ./assets/arcaea ' )
2021-04-28 11:01:25 +00:00
def text_border ( draw , x , y , text , shadowcolor , fillcolor , font ) :
x = x + 2
y = y + 2
# thin border
draw . text ( ( x - 2 , y ) , text , font = font , fill = shadowcolor )
draw . text ( ( x + 2 , y ) , text , font = font , fill = shadowcolor )
draw . text ( ( x , y - 2 ) , text , font = font , fill = shadowcolor )
draw . text ( ( x , y + 2 ) , text , font = font , fill = shadowcolor )
# thicker border
draw . text ( ( x - 2 , y - 2 ) , text , font = font , fill = shadowcolor )
draw . text ( ( x + 2 , y - 2 ) , text , font = font , fill = shadowcolor )
draw . text ( ( x - 2 , y + 2 ) , text , font = font , fill = shadowcolor )
draw . text ( ( x + 2 , y + 2 ) , text , font = font , fill = shadowcolor )
# now draw the text over it
draw . text ( ( x , y ) , text , font = font , fill = fillcolor )
def makeShadow ( image , iterations , border , offset , backgroundColour , shadowColour ) :
fullWidth = image . size [ 0 ] + abs ( offset [ 0 ] ) + 2 * border
fullHeight = image . size [ 1 ] + abs ( offset [ 1 ] ) + 2 * border
shadow = Image . new ( image . mode , ( fullWidth , fullHeight ) , backgroundColour )
shadowLeft = border + max ( offset [ 0 ] , 0 )
shadowTop = border + max ( offset [ 1 ] , 0 )
shadow . paste ( shadowColour ,
[ shadowLeft , shadowTop ,
shadowLeft + image . size [ 0 ] ,
shadowTop + image . size [ 1 ] ] )
for i in range ( iterations ) :
shadow = shadow . filter ( ImageFilter . BLUR )
imgLeft = border - min ( offset [ 0 ] , 0 )
imgTop = border - min ( offset [ 1 ] , 0 )
shadow . paste ( image , ( imgLeft , imgTop ) )
return shadow
2022-01-19 17:02:23 +00:00
def drawb30 ( Username , b30 , r10 , ptt , character , path = ' ' , official = False ) :
2021-04-28 11:01:25 +00:00
# backgroud
2022-01-19 17:02:23 +00:00
if not official :
bgimgpath = f ' { assets_path } /world/ '
else :
bgimgpath = f ' { assets_path } /world_official/ '
2021-05-28 15:30:05 +00:00
bglist = os . listdir ( bgimgpath )
2021-08-07 07:56:48 +00:00
bgr = random . randint ( 0 , len ( bglist ) - 1 )
2021-05-28 16:07:20 +00:00
bg = Image . open ( bgimgpath + f ' / { bglist [ bgr ] } ' ) . convert ( " RGBA " )
2021-05-28 15:30:05 +00:00
bg = bg . resize ( ( bg . size [ 0 ] * 2 , bg . size [ 1 ] * 2 ) )
2021-05-28 16:06:00 +00:00
offset = random . randint ( 0 , 1024 )
2022-01-19 17:02:23 +00:00
if not official :
b30img = bg . crop ( ( 0 , offset , 2489 , 1400 + offset ) )
else :
b30img = bg . crop ( ( 0 , offset , 1975 , 1610 + offset ) )
if not official :
# triangle
tg = Image . open ( f ' { assets_path } /triangle.png ' )
b30img . alpha_composite ( tg . convert ( " RGBA " ) , ( 1580 , 550 ) )
# character
try :
character = Image . open ( f ' { assets_path } /char/ { str ( character ) } .png ' )
b30img . alpha_composite ( character . convert ( " RGBA " ) , ( 1660 , 350 ) )
except Exception :
pass
2021-04-28 11:01:25 +00:00
# usercard overlay
2021-05-30 06:06:41 +00:00
cardoverlay = Image . open ( f ' { assets_path } /card_overlay.png ' )
2022-01-19 17:02:23 +00:00
if not official :
b30img . alpha_composite ( cardoverlay . convert ( " RGBA " ) , ( 1750 , 1227 ) )
else :
b30img . alpha_composite ( makeShadow ( cardoverlay . convert ( " RGBA " ) , 2 , 3 , [ 3 , 3 ] , ' rgba(0,0,0,0) ' , ' #000000 ' ) , ( b30img . width - 500 , 68 ) )
2021-04-28 11:01:25 +00:00
# ptt
if ptt > = 12.50 :
pttimg = 6
elif ptt > = 12.00 :
pttimg = 5
elif ptt > = 11.00 :
pttimg = 4
elif ptt > = 10.00 :
pttimg = 3
elif ptt > = 7.00 :
pttimg = 2
elif ptt > = 3.50 :
pttimg = 1
elif ptt > = 0 :
pttimg = 0
else :
pttimg = ' off '
2021-05-30 06:06:41 +00:00
pttimg = Image . open ( f ' { assets_path } /ptt/rating_ { str ( pttimg ) } .png ' )
2021-04-28 11:01:25 +00:00
pttimg = pttimg . resize ( ( 75 , 75 ) )
2022-01-19 17:02:23 +00:00
if not official :
b30img . alpha_composite ( pttimg . convert ( " RGBA " ) , ( 1775 , 1226 ) )
else :
b30img . alpha_composite ( pttimg . convert ( " RGBA " ) , ( b30img . width - 450 , 67 ) )
2021-04-28 11:01:25 +00:00
ptttext = Image . new ( " RGBA " , ( 200 , 200 ) )
2021-05-30 06:06:41 +00:00
font1 = ImageFont . truetype ( f ' { assets_path } /Fonts/Exo-SemiBold.ttf ' , 30 )
font2 = ImageFont . truetype ( f ' { assets_path } /Fonts/Exo-SemiBold.ttf ' , 21 )
2021-04-28 11:01:25 +00:00
rawptt = str ( ptt ) . split ( ' . ' )
ptt1 = rawptt [ 0 ]
ptt2 = rawptt [ 1 ]
if len ( ptt2 ) < 2 :
ptt2 + = ' 0 '
ptttext_width , ptttext_height = ptttext . size
font1_width , font1_height = font1 . getsize ( ptt1 + ' . ' )
font2_width , font2_height = font2 . getsize ( ptt2 )
print ( font1_width , font1_height )
2021-04-28 13:07:11 +00:00
print ( font2_width , font2_height )
2021-05-28 15:39:39 +00:00
pttimg = Image . new ( " RGBA " , ( font1_width + font2_width + 4 , font1_height + 4 ) )
2021-04-28 11:01:25 +00:00
drawptt = ImageDraw . Draw ( pttimg )
text_border ( drawptt , 0 , 0 ,
2021-05-28 15:39:39 +00:00
ptt1 + ' . ' ,
2021-04-28 11:01:25 +00:00
' #52495d ' , ' white ' , font = font1 )
2021-05-28 15:39:39 +00:00
print ( int ( int ( font1_height ) - int ( font2_height ) ) )
2021-04-28 11:01:25 +00:00
text_border ( drawptt , font1_width , 9 , ptt2 ,
' #52495d ' , ' white ' , font = font2 )
pttimg_width , pttimg_height = pttimg . size
2021-05-28 15:39:39 +00:00
ptttext . alpha_composite ( pttimg ,
( int ( ( ptttext_width - pttimg_width ) / 2 ) , int ( ( ptttext_height - pttimg_height ) / 2 ) ) )
2022-01-19 17:02:23 +00:00
if not official :
b30img . alpha_composite ( ptttext , ( 1712 , 1157 ) )
else :
b30img . alpha_composite ( ptttext , ( b30img . width - 514 , - 2 ) )
2021-04-28 11:01:25 +00:00
# username
2021-05-30 06:06:41 +00:00
userfont = ImageFont . truetype ( f ' { assets_path } /Fonts/GeosansLight.ttf ' , 45 )
2021-04-28 11:01:25 +00:00
textdraw = ImageDraw . Draw ( b30img )
2022-01-19 17:02:23 +00:00
if not official :
text_border ( textdraw , 1871 , 1225 , Username , ' white ' , ' #3a4853 ' , font = userfont )
else :
text_border ( textdraw , b30img . width - 170 - textdraw . textsize ( Username , font = userfont ) [ 0 ] , 66 , Username , ' white ' , ' #3a4853 ' , font = userfont )
2021-04-28 11:01:25 +00:00
# b30
2021-05-30 06:06:41 +00:00
b30font = ImageFont . truetype ( f ' { assets_path } /Fonts/Exo-Medium.ttf ' , 17 )
2022-01-19 17:02:23 +00:00
br30 = f ' B30: { str ( b30 ) } R10: { str ( r10 ) } '
if not official :
text_border ( textdraw , 1876 , 1270 , f ' B30: { str ( b30 ) } R10: { str ( r10 ) } ' , ' white ' , ' #3a4853 ' , font = b30font )
else :
2022-01-20 00:29:59 +00:00
text_border ( textdraw , b30img . width - 360 , 112 , br30 , ' white ' , ' #3a4853 ' , font = b30font )
2022-01-19 17:02:23 +00:00
# disclaimer
disclaimer_font = ImageFont . truetype ( f ' { assets_path } /Fonts/Exo-Medium.ttf ' , 25 )
if official :
2022-01-20 03:46:14 +00:00
text_border ( textdraw , 5 , 5 , f ' Based on ArcaeaLimitedAPI by Lowiro | Generated by Teahouse Studios " Akaribot " '
2022-01-19 17:02:23 +00:00
f ' \n This service utilizes API functionality provided by and with permission from lowiro. It is not affiliated with or endorsed by lowiro. ' , ' white ' , ' #3a4853 ' , font = b30font )
else :
2022-01-20 03:46:14 +00:00
text_border ( textdraw , b30img . width - 490 , 5 , f ' Based on BotArcAPI | Generated by Teahouse Studios " Akaribot " ' , ' white ' , ' #3a4853 ' , font = b30font )
2021-04-28 11:01:25 +00:00
# b30card
i = 0
fname = 1
t = 0
s = 0
while True :
try :
cardimg = Image . open ( os . path . abspath ( f ' { path } / { str ( fname ) } .png ' ) )
2022-01-19 17:02:23 +00:00
w = ( 15 if not official else 115 ) + 345 * i
h = ( 15 if not official else 185 )
2021-04-28 11:01:25 +00:00
if s == 5 :
s = 0
t + = 1
h = h + 220 * t
w = w - 345 * 5 * t
i + = 1
cardimg = makeShadow ( cardimg , 4 , 9 , [ 0 , 3 ] , ' rgba(0,0,0,0) ' , ' #000000 ' )
b30img . alpha_composite ( cardimg , ( w , h ) )
fname + = 1
s + = 1
except FileNotFoundError :
break
except Exception :
traceback . print_exc ( )
break
if __name__ == ' __main__ ' :
b30img . show ( )
else :
savefilename = os . path . abspath ( f ' ./cache/ { str ( uuid . uuid4 ( ) ) } .jpg ' )
b30img . convert ( " RGB " ) . save ( savefilename )
return savefilename
if __name__ == ' __main__ ' :
2022-01-20 03:46:14 +00:00
drawb30 ( ' OasisAkari ' , ' 10.250 ' , ' 10.250 ' , 12.31 , ' 0 ' , official = False )