Advertisement
nikolask

CS50P - PSET8_shirtificate_1

Sep 15th, 2023
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | Source Code | 0 0
  1. # https://cs50.harvard.edu/python/2022/psets/8/shirtificate/
  2.  
  3. from fpdf import FPDF, Align
  4. from PIL import Image, ImageFont, ImageDraw
  5.  
  6. user_name = input("Name: ")
  7. text = f"{user_name} took CS50"
  8.  
  9. img = Image.open("shirtificate.png")
  10. myFont = ImageFont.truetype("Arial", size=24)
  11. new_img = ImageDraw.Draw(img)
  12. new_img = img.resize((round(img.size[0] * 0.91), round(img.size[1] * 0.91)))
  13. width, height = new_img.size
  14. length = myFont.getlength(text)
  15. ImageDraw.Draw(new_img).text(
  16.     ((width - length) / 2, (height - 25) / 3), text, fill=(255, 255, 255), font=myFont
  17. )
  18.  
  19. # pdf
  20. shirt_pdf = FPDF("P", "mm", "A4")
  21. shirt_pdf.add_page()
  22. shirt_pdf.set_font("helvetica", "", 48)
  23. shirt_pdf.cell(0, 50, "CS50 Shirtificate", align="C")
  24. shirt_pdf.image(new_img, x=Align.C, y=70)
  25.  
  26.  
  27. shirt_pdf.output("shirtificate.pdf")
  28.  
Tags: CS50P
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement