ChenyuRabbitLove commited on
Commit
00cc093
โ€ข
1 Parent(s): 16b807e

bugfix: fix minor bugs

Browse files
Files changed (2) hide show
  1. css/style.css +1 -1
  2. utils/completion_reward.py +29 -27
css/style.css CHANGED
@@ -381,7 +381,7 @@ input[type="range"]::-ms-track {
381
  }
382
 
383
  .code_wrap pre {
384
- background: none;
385
  }
386
 
387
  #certificate [aria-label="Download"]{
 
381
  }
382
 
383
  .code_wrap pre {
384
+ background: none !important;
385
  }
386
 
387
  #certificate [aria-label="Download"]{
utils/completion_reward.py CHANGED
@@ -478,45 +478,47 @@ class ImageProcessor:
478
  tmp_img = Image.new("RGBA", img.size, (0, 0, 0, 0))
479
  draw = ImageDraw.Draw(tmp_img)
480
 
481
- # Draw the box
 
 
 
 
 
 
 
 
482
  left, right = 50, img.width - 50
483
- box_height = 600
 
 
 
 
 
 
 
 
 
 
 
 
484
  top = (img.height - box_height) // 2
485
  bottom = (img.height + box_height) // 2
486
- border_radius = 20
487
 
488
  # Draw the rounded rectangle
 
489
  fill_color = (255, 255, 255, 200)
490
- draw.rounded_rectangle(
491
- [left, top, right, bottom],
492
- fill=fill_color,
493
- outline=None,
494
- radius=border_radius,
495
- )
496
-
497
- img.paste(Image.alpha_composite(img.convert("RGBA"), tmp_img), (0, 0), tmp_img)
498
-
499
- draw = ImageDraw.Draw(img)
500
-
501
- # Draw the text
502
- title_font = ImageFont.truetype("NotoSansTC-Bold.ttf", 34)
503
- body_font = ImageFont.truetype("NotoSansTC-Light.ttf", 14)
504
 
505
- # Title text
506
- title = f"ๅ…‰ๆŸๅฎˆ่ญท่€… - {player_name} ็š„ๅ†’้šชๆ•…ไบ‹"
507
- title_x, title_y = left + 20, top + 20 # Adjust padding as needed
508
- draw.text((title_x, title_y), title, font=title_font, fill="black")
509
-
510
- # Paragraph text with newlines
511
- body_x, body_y = left + 20, title_y + 60 # Adjust position as needed
512
 
 
 
513
  for line in paragraph.split("\n"):
514
  wrapped_lines = textwrap.wrap(line, width=60)
515
  for wrapped_line in wrapped_lines:
516
  draw.text((body_x, body_y), wrapped_line, font=body_font, fill="black")
517
- body_y += 25
518
-
519
- # Save the image with the text
520
 
521
  def get_md5_hash(text):
522
  return hashlib.md5(text.encode("utf-8")).hexdigest()
 
478
  tmp_img = Image.new("RGBA", img.size, (0, 0, 0, 0))
479
  draw = ImageDraw.Draw(tmp_img)
480
 
481
+ # Fonts
482
+ title_font = ImageFont.truetype("NotoSansTC-Bold.ttf", 34)
483
+ body_font = ImageFont.truetype("NotoSansTC-Light.ttf", 14)
484
+
485
+ # Text contents
486
+ title = f"ๅ…‰ๆŸๅฎˆ่ญท่€… - {player_name} ็š„ๅ†’้šชๆ•…ไบ‹"
487
+ paragraph = "Your long paragraph text goes here..." # Replace with your paragraph
488
+
489
+ # Calculate text size
490
  left, right = 50, img.width - 50
491
+ title_x, title_y = left + 20, 20 # Title position
492
+ body_x, body_y = left + 20, title_y + 60 # Body position
493
+
494
+ # Calculate space required by the paragraph
495
+ paragraph_height = 0
496
+ for line in paragraph.split("\n"):
497
+ wrapped_lines = textwrap.wrap(line, width=60)
498
+ for wrapped_line in wrapped_lines:
499
+ paragraph_height += body_font.getsize(wrapped_line)[1] + 25
500
+
501
+ # Calculate box height and top, bottom position
502
+ padding = 40 # Additional padding
503
+ box_height = max(600, paragraph_height + padding) # Minimum height or paragraph height
504
  top = (img.height - box_height) // 2
505
  bottom = (img.height + box_height) // 2
 
506
 
507
  # Draw the rounded rectangle
508
+ border_radius = 20
509
  fill_color = (255, 255, 255, 200)
510
+ draw.rounded_rectangle([left, top, right, bottom], fill=fill_color, outline=None, radius=border_radius)
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
+ # Draw the title text
513
+ draw.text((title_x, top + 20), title, font=title_font, fill="black")
 
 
 
 
 
514
 
515
+ # Draw the paragraph text
516
+ body_y = top + 60 + title_font.getsize(title)[1]
517
  for line in paragraph.split("\n"):
518
  wrapped_lines = textwrap.wrap(line, width=60)
519
  for wrapped_line in wrapped_lines:
520
  draw.text((body_x, body_y), wrapped_line, font=body_font, fill="black")
521
+ body_y += body_font.getsize(wrapped_line)[1] + 25
 
 
522
 
523
  def get_md5_hash(text):
524
  return hashlib.md5(text.encode("utf-8")).hexdigest()