diff --git a/images/main/black-suit.png b/images/main/black-suit.png deleted file mode 100644 index e4a593e..0000000 Binary files a/images/main/black-suit.png and /dev/null differ diff --git a/images/main/shannon.jpg b/images/main/shannon.jpg new file mode 100644 index 0000000..aa3060c Binary files /dev/null and b/images/main/shannon.jpg differ diff --git a/main.py b/main.py index ec3039f..d45de10 100644 --- a/main.py +++ b/main.py @@ -13,24 +13,20 @@ from email.mime.image import MIMEImage app = Flask(__name__) def add_textimg(text, code): - def generatePath(): - some_id = random.randint(2000, 9000) - return f"images/output/pos-{str(some_id)}.png" - - path = generatePath() + path = f"images/output/pos-{str(code)}.jpg" try: - img = Image.open("images/main/black-suit.png") + img = Image.open("images/main/shannon.jpg") draw = ImageDraw.Draw(img) - font = ImageFont.truetype("fonts/impact.ttf", 52) + font = ImageFont.truetype("fonts/impact.ttf", 24) text_pos1_center = (img.width - draw.textlength(text, font)) // 2 text_pos2_center = (img.width - draw.textlength(code, font)) // 2 text_pos_bottom = img.height - pos1 = (text_pos1_center, text_pos_bottom - 200) - pos2 = (text_pos2_center, text_pos_bottom - 130) + pos1 = (text_pos1_center, text_pos_bottom - 90) + pos2 = (text_pos2_center, text_pos_bottom - 60) text_color = (255, 255, 255) draw.text(pos1, text, fill=text_color, font=font) @@ -38,9 +34,6 @@ def add_textimg(text, code): if not os.path.exists("images/output"): os.mkdir("images/output") - - while os.path.exists(path): - path = generatePath() img.save(path) img.close() @@ -56,7 +49,7 @@ def hello(): def generate_otp(): try: randis = random.randint(1000, 9999) - add_textimg(f"Your confirmation code is", str(randis)) + add_textimg(f"Your verification code is", str(randis)) return jsonify({"status": "ok"}) except Exception as e: @@ -96,9 +89,9 @@ def send_email(): zmail.attach(MIMEText(msg, 'plain')) # attach picure - add_textimg(f"Your confirmation code is", str(randis)) - pict = open("images/output/pos.png", "rb").read() - zmail.attach(MIMEImage(pict, name="black-man-wearing-suit.png")) + add_textimg("Your verification code is", str(randis)) + pict = open(f"images/output/pos-{str(randis)}.jpg", "rb").read() + zmail.attach(MIMEImage(pict, name="black-man-wearing-suit.jpg")) # creating context context = ssl.create_default_context()