reduce image size
This commit is contained in:
parent
e782d7294c
commit
d868e72836
Binary file not shown.
Before Width: | Height: | Size: 408 KiB |
BIN
images/main/shannon.jpg
Normal file
BIN
images/main/shannon.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
25
main.py
25
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user