Spaces:
Sleeping
Sleeping
Update chroma/chroma/utility/chroma.py
Browse files- 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=
|
|
|
|
|
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 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
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
|