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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def add_textimg(text, code):
|
def add_textimg(text, code):
|
||||||
def generatePath():
|
path = f"images/output/pos-{str(code)}.jpg"
|
||||||
some_id = random.randint(2000, 9000)
|
|
||||||
return f"images/output/pos-{str(some_id)}.png"
|
|
||||||
|
|
||||||
path = generatePath()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img = Image.open("images/main/black-suit.png")
|
img = Image.open("images/main/shannon.jpg")
|
||||||
draw = ImageDraw.Draw(img)
|
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_pos1_center = (img.width - draw.textlength(text, font)) // 2
|
||||||
text_pos2_center = (img.width - draw.textlength(code, font)) // 2
|
text_pos2_center = (img.width - draw.textlength(code, font)) // 2
|
||||||
|
|
||||||
text_pos_bottom = img.height
|
text_pos_bottom = img.height
|
||||||
|
|
||||||
pos1 = (text_pos1_center, text_pos_bottom - 200)
|
pos1 = (text_pos1_center, text_pos_bottom - 90)
|
||||||
pos2 = (text_pos2_center, text_pos_bottom - 130)
|
pos2 = (text_pos2_center, text_pos_bottom - 60)
|
||||||
text_color = (255, 255, 255)
|
text_color = (255, 255, 255)
|
||||||
|
|
||||||
draw.text(pos1, text, fill=text_color, font=font)
|
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"):
|
if not os.path.exists("images/output"):
|
||||||
os.mkdir("images/output")
|
os.mkdir("images/output")
|
||||||
|
|
||||||
while os.path.exists(path):
|
|
||||||
path = generatePath()
|
|
||||||
|
|
||||||
img.save(path)
|
img.save(path)
|
||||||
img.close()
|
img.close()
|
||||||
@ -56,7 +49,7 @@ def hello():
|
|||||||
def generate_otp():
|
def generate_otp():
|
||||||
try:
|
try:
|
||||||
randis = random.randint(1000, 9999)
|
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"})
|
return jsonify({"status": "ok"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -96,9 +89,9 @@ def send_email():
|
|||||||
zmail.attach(MIMEText(msg, 'plain'))
|
zmail.attach(MIMEText(msg, 'plain'))
|
||||||
|
|
||||||
# attach picure
|
# attach picure
|
||||||
add_textimg(f"Your confirmation code is", str(randis))
|
add_textimg("Your verification code is", str(randis))
|
||||||
pict = open("images/output/pos.png", "rb").read()
|
pict = open(f"images/output/pos-{str(randis)}.jpg", "rb").read()
|
||||||
zmail.attach(MIMEImage(pict, name="black-man-wearing-suit.png"))
|
zmail.attach(MIMEImage(pict, name="black-man-wearing-suit.jpg"))
|
||||||
|
|
||||||
# creating context
|
# creating context
|
||||||
context = ssl.create_default_context()
|
context = ssl.create_default_context()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user