resize image based width to keep the text size
This commit is contained in:
parent
b8609c9c6d
commit
e9ad8c23b3
15
main.py
15
main.py
@ -12,14 +12,25 @@ from email.mime.image import MIMEImage
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
INPUT_IMG_PATH = "images/main/shannon.jpg"
|
INPUT_IMG_PATH = "images/main/shannon.jpg" # image path
|
||||||
OUTPUT_IMG_NAME = "black-man-wearing-suit.jpg"
|
OUTPUT_IMG_NAME = "black-man-wearing-suit.jpg" # name of the file to be added in the email
|
||||||
|
|
||||||
|
# this is actually useless cuz Pillow has provided a thumbnail function to keep the aspect ratio
|
||||||
|
def resize(in_width, in_height):
|
||||||
|
out_width = 270
|
||||||
|
out_height = in_height * (out_width / in_width)
|
||||||
|
out_size = (int(out_width), int(out_height))
|
||||||
|
|
||||||
|
return out_size
|
||||||
|
|
||||||
def add_textimg(text, code):
|
def add_textimg(text, code):
|
||||||
path = f"images/output/pos-{str(code)}.jpg"
|
path = f"images/output/pos-{str(code)}.jpg"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img = Image.open(INPUT_IMG_PATH)
|
img = Image.open(INPUT_IMG_PATH)
|
||||||
|
new_size = resize(img.width, img.height)
|
||||||
|
img = img.resize(new_size)
|
||||||
|
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
font = ImageFont.truetype("fonts/impact.ttf", 24)
|
font = ImageFont.truetype("fonts/impact.ttf", 24)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user