Skip to content

Commit

Permalink
Working program
Browse files Browse the repository at this point in the history
  • Loading branch information
imacrazyguylol committed May 10, 2023
1 parent c6fa461 commit 710faa2
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions imagegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __modIcons(score: Score):
im.paste(modIcon, (i * 91, 0))
i += 1 # python should have increment/decrement :(

return im

return im
def imageGen(score: Score):
# open background into bkgImage
beatmapset_id = score.beatmapset.id
Expand All @@ -77,7 +77,6 @@ def imageGen(score: Score):
# avatarImage = avatarImage.resize((192, 192)) # only if 720p
avatarImage = __roundCorners(avatarImage, 35)

# avatarImage.save('tempavatar.png')
os.remove(os.path.abspath(os.getcwd()) + '/tempavatar.jpg')

# open ranking icon
Expand Down Expand Up @@ -105,41 +104,45 @@ def imageGen(score: Score):

# Artist - Title; centered towards the top
length = draw.textlength(f'{score.beatmapset.artist} - {score.beatmapset.title}', font=getFont(96))
draw.text( ( (1920 - length)/2, 142 ), f'{score.beatmapset.artist} - {score.beatmapset.title}', fill='white', font=getFont(96), stroke_width=2, stroke_fill='black' )
draw.text( ( (1920 - length)/2, 60 ), f'{score.beatmapset.artist} - {score.beatmapset.title}', fill='white', font=getFont(96), stroke_width=2, stroke_fill='black' )

# [Difficulty]; smaller text, right under artist/title
length = draw.textlength(f'[{score.beatmap.version}]', font=getFont(64))
draw.text( ( (1920 - length)/2, 262 ), f'[{score.beatmap.version}]', fill='white', font=getFont(64), stroke_width=2, stroke_fill='black' )
draw.text( ( (1920 - length)/2, 180 ), f'[{score.beatmap.version}]', fill='white', font=getFont(64), stroke_width=2, stroke_fill='black' )

# ###pp; might be worth trying to make the pp number a diff color later
length = draw.textlength(f'{round(score.pp)}pp', font=tempFont)
draw.text( ( (1920 - length)/2 - 256, 360 ), f'{round(score.pp)}pp', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')
draw.text( ( 800 - length, 360 ), f'{round(score.pp)}pp', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

# ### BPM;
# ### BPM; subtracting length aligns text to right
length = draw.textlength(f'{score.beatmap.bpm} BPM', font=tempFont)
draw.text( ( (1920 - length)/2 - 256, 480 ), f'{score.beatmap.bpm} BPM', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')
draw.text( ( 800 - length, 480 ), f'{score.beatmap.bpm} BPM', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

# ##.##%; acc
length = draw.textlength(f'{score.accuracy}%', font=tempFont)
draw.text( ( (1920 - length)/2 - 256, 600 ), f'{score.accuracy}%', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')
length = draw.textlength(f'{(score.accuracy * 100):.2f}%', font=tempFont)
draw.text( ( 800 - length, 600 ), f'{(score.accuracy * 100):.2f}%', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

# Username;
length = draw.textlength(f'{score.user().username}', font=tempFont)
draw.text( ( (1920 - length)/2 + 256, 360 ), f'{score.user().username}', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')
draw.text( ( 1120, 360 ), f'{score.user().username}', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

# #.##☆; sr
length = draw.textlength(f'{score.beatmap.difficulty_rating}☆', font=tempFont) # accounts for star placement as well
draw.text( ( (1920 - length)/2 + 256, 480 ), f'{score.beatmap.difficulty_rating}', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

# ####x; combo
length = draw.textlength(f'{score.max_combo}x', font=tempFont)
draw.text( ( (1920 - length)/2 + 256, 600 ), f'{score.max_combo}x', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')
length = draw.textlength(f'{score.beatmap.difficulty_rating}', font=tempFont) # accounts for star placement as well
draw.text( ( 1120, 480 ), f'{score.beatmap.difficulty_rating}', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

star = Image.open('src/SRstar.png').resize((64, 64)).convert('RGBA')
output.paste(star, (1124 + round(length), 480), star)

# ####x; combo
draw.text( ( 1120, 600 ), f'{score.max_combo}x', fill='white', font=tempFont, stroke_width=2, stroke_fill='black')

# comment;
comment = input("Enter the comment to be added. If none, leave blank. For multiline comments, use newline (\\n) characters. \n> ")
if comment:
length = draw.textlength(comment, font=getFont(80))
draw.text( ( (1920 - length)/2, 840), comment, fill='white', font=getFont(80), stroke_width=2, stroke_fill='black')

output.save('output/thumbnail.png')
output.show()

# os.remove(os.path.abspath(os.getcwd()) + '/tempbkg.png')
# os.remove(os.path.abspath(os.getcwd()) + '/tempavatar.png')

# return path to final output

0 comments on commit 710faa2

Please sign in to comment.