salahIguiliz commited on
Commit
56e36e2
·
1 Parent(s): 1db7700

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -62,26 +62,30 @@ def get_pose(image):
62
 
63
 
64
  def generate_an_image_from_text(text, text_size_, width, lenght):
65
- # Create a blank image
66
- image = Image.new('RGB', (width, lenght), color = (255, 255, 255))
67
- # Create a drawing object
68
- draw = ImageDraw.Draw(image)
69
- # font def
70
- font_dir = '/usr/share/fonts/truetype/liberation/'
71
- # Get a list of all the font files in the directory
72
- font_files = [os.path.join(font_dir, f) for f in os.listdir(font_dir) if os.path.isfile(os.path.join(font_dir, f))]
73
- # Select a random font
74
- font_path = random.choice(font_files)
75
- #print(font_path)
76
- font = ImageFont.truetype(font_path, text_size_)
77
- # Get the text size
78
- text_size = draw.textsize(text, font)
79
- # Calculate the x and y positions for the text
80
- x = (image.width - text_size[0]) / 2
81
- y = (image.height - text_size[1]) / 2
82
- # Draw the text on the image
83
- draw.text((x, y), text, fill=(0, 0, 0), font=font)
84
- return image
 
 
 
 
85
 
86
  def to_Canny(image):
87
  # Let's load the popular vermeer image
 
62
 
63
 
64
  def generate_an_image_from_text(text, text_size_, width, lenght):
65
+ # Create a blank image
66
+ image = Image.new('RGB', (width, lenght), color = (255, 255, 255))
67
+ # Create a drawing object
68
+ draw = ImageDraw.Draw(image)
69
+ # font def
70
+ font_dir = ''
71
+ # Get a list of all the font files in the directory
72
+ font_files = glob.glob(os.path.join(dir_path, 'fonts', '*.ttf'))
73
+ # Get a list of font paths
74
+ font_paths = []
75
+ for font_file in font_files:
76
+ font_paths.append(font_file)
77
+ # Select a random font
78
+ font_path = random.choice(font_paths)
79
+ #print(font_path)
80
+ font = ImageFont.truetype(font_path, text_size_)
81
+ # Get the text size
82
+ text_size = draw.textsize(text, font)
83
+ # Calculate the x and y positions for the text
84
+ x = (image.width - text_size[0]) / 2
85
+ y = (image.height - text_size[1]) / 2
86
+ # Draw the text on the image
87
+ draw.text((x, y), text, fill=(0, 0, 0), font=font)
88
+ return image
89
 
90
  def to_Canny(image):
91
  # Let's load the popular vermeer image