text in image manipulation

This commit is contained in:
Nomi Nonsense (Nonszy) 2023-09-07 22:44:34 +07:00
parent 6e6b0a0d75
commit 6e6a4c014f
3 changed files with 18 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.env
images/output/*

BIN
fonts/impact.ttf Normal file

Binary file not shown.

17
main.py
View File

@ -3,6 +3,8 @@ import random
import ssl
import smtplib
from PIL import Image, ImageDraw, ImageFont
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
@ -11,6 +13,19 @@ mail_sender = "norman25.projects2@gmail.com"
mail_password = os.environ.get("EMAIL_PASSWORD_2")
mail_receiver = "norman25.na@gmail.com"
def add_textimg(text):
img = Image.open("images/main/black-suit.png")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("fonts/impact.ttf", 64)
text_pos_center = (img.width - draw.textlength(text, font)) // 2
pos = (text_pos_center, 720)
text_color = (255, 255, 255)
draw.text(pos, text, fill=text_color, font=font)
img.save("images/output/pos.png")
img.close()
def send_email():
try:
randis = random.randint(1000, 9999)
@ -41,4 +56,4 @@ def send_email():
print("Failed to send a email")
print(str(e))
send_email()
add_textimg("Your otp code is 3826")