Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
node_modules/
29 changes: 29 additions & 0 deletions imgGenerator/python/genImg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests
import json
from PIL import Image, ImageDraw, ImageFont

url = "http://localhost:4000/genImg"
headers = {'Content-Type': 'application/json'}
r = requests.get(url, headers=headers)
data = r.json()
data = json.loads(data)
print(data["tip"])
img = Image.new('RGB', (300, 300), color=(73, 109, 137))
fnt = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', 8)
fontsize = 1
fnt2 = ImageFont.truetype(
'/usr/share/fonts/truetype/freefont/FreeSerif.ttf', fontsize)
while fnt2.getsize(data["tip"])[0] < 0.5*img.size[0]:
# iterate until the text size is just larger than the criteria
fontsize += 1
fnt2 = ImageFont.truetype(
'/usr/share/fonts/truetype/freefont/FreeSerif.ttf', fontsize)

# optionally de-increment to be sure it is less than criteria
fnt2 = ImageFont.truetype(
'/usr/share/fonts/truetype/freefont/FreeSerif.ttf', fontsize)
d = ImageDraw.Draw(img)
d.text((10, 10), data["hastags"], font=fnt, fill=(255, 255, 0))
d.text((10, 40), data["tip"], font=fnt2, fill=(255, 255, 0))

img.save('pil_text_font.png')
Binary file added imgGenerator/python/pil_text_font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions imgGenerator/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
init the server first in the scripts folder

then init the genimg script with python3 genimg.py in linux
Empty file added scripts/.gitignore
Empty file.
Loading