Hukuna commited on
Commit
a594b8e
·
verified ·
1 Parent(s): 39c5094

Update chroma/chroma/utility/chroma.py

Browse files
Files changed (1) hide show
  1. chroma/chroma/utility/chroma.py +23 -21
chroma/chroma/utility/chroma.py CHANGED
@@ -30,7 +30,9 @@ from chroma.layers.structure import backbone
30
  def letter_to_point_cloud(
31
  letter="G",
32
  width_pixels=35,
33
- font="FreeMono.ttf",
 
 
34
  depth_ratio=0.15,
35
  fontsize_ratio=1.2,
36
  stroke_width=1,
@@ -40,26 +42,26 @@ def letter_to_point_cloud(
40
  """Build a point cloud from a letter"""
41
  depth = int(depth_ratio * width_pixels)
42
  fontsize = int(fontsize_ratio * width_pixels)
43
-
44
- font = ImageFont.truetype("arial.ttf", 15)
45
- ascent, descent = font.getmetrics()
46
- text_width = font.getmask(letter).getbbox()[2]
47
- text_height = font.getmask(letter).getbbox()[3] + descent
48
-
49
- margin_width = int(text_width * margin)
50
- margin_height = int(text_height * margin)
51
- image_size = [text_width + margin_width, text_height + margin_height]
52
-
53
- image = Image.new("RGBA", image_size, (255, 255, 255))
54
- draw = ImageDraw.Draw(image)
55
- draw.text(
56
- (margin_width // 2, margin_height // 2),
57
- letter,
58
- (0, 0, 0),
59
- font=font,
60
- stroke_width=stroke_width,
61
- stroke_fill="black",
62
- )
63
 
64
  A = np.asarray(image).mean(-1)
65
  A = A < 100.0
 
30
  def letter_to_point_cloud(
31
  letter="G",
32
  width_pixels=35,
33
+ font = os.path.join(
34
+ os.path.dirname(chroma.__path__[0]), "./assets/LiberationSans-Regular.ttf"
35
+ ),
36
  depth_ratio=0.15,
37
  fontsize_ratio=1.2,
38
  stroke_width=1,
 
42
  """Build a point cloud from a letter"""
43
  depth = int(depth_ratio * width_pixels)
44
  fontsize = int(fontsize_ratio * width_pixels)
45
+ with ImageFont.truetype(font_path, size) as font:
46
+ # font = ImageFont.truetype("arial.ttf", 15)
47
+ ascent, descent = font.getmetrics()
48
+ text_width = font.getmask(letter).getbbox()[2]
49
+ text_height = font.getmask(letter).getbbox()[3] + descent
50
+
51
+ margin_width = int(text_width * margin)
52
+ margin_height = int(text_height * margin)
53
+ image_size = [text_width + margin_width, text_height + margin_height]
54
+
55
+ image = Image.new("RGBA", image_size, (255, 255, 255))
56
+ draw = ImageDraw.Draw(image)
57
+ draw.text(
58
+ (margin_width // 2, margin_height // 2),
59
+ letter,
60
+ (0, 0, 0),
61
+ font=font,
62
+ stroke_width=stroke_width,
63
+ stroke_fill="black",
64
+ )
65
 
66
  A = np.asarray(image).mean(-1)
67
  A = A < 100.0