Commits

J.A. Roberts Tunney  committed 49d3a5f

include free helvetica, make text shadow look better on white/black backgrounds

  • Participants
  • Parent commits dba65e9

Comments (0)

Files changed (3)

File fabulous/fonts/IndUni-H-Bold.otf

Binary file added.

File fabulous/image.py

 class Image(object):
     pad = ' '
 
-    def __init__(self, path, width=None, bgcolor='black'):
+    def __init__(self, path, width=None, bgcolor='white'):
         self.img = Pills.open(path)
         self.bgcolor = Color.NewFromHtml(bgcolor)
         self.resize(width)

File fabulous/text.py

+
+import os
 
 from grapefruit import Color
 from PIL import Image, ImageFont, ImageDraw
 from fabulous import image, color
 
 
+DEFAULT_FONT = os.path.join(os.path.dirname(__file__), 'fonts', 'IndUni-H-Bold.otf')
+
+
 class Text(image.Image):
-    def __init__(self, text, fsize=20, color="#0099ff", bgcolor='black',
-                 shadow=False, scew=None):
+    def __init__(self, text, fsize=20, color="#0099ff", font=DEFAULT_FONT,
+                 bgcolor='black', shadow=False, scew=None):
         self.text = text
         self.color = Color.NewFromHtml(color)
         self.bgcolor = Color.NewFromHtml(bgcolor)
-        self.font = ImageFont.truetype(r'/home/jart/.fonts/IndUni-H-Bold.otf', fsize)
-        # self.font = ImageFont.truetype(r'/home/jart/.fonts/LokiCola.ttf', fsize)
-        # self.font = ImageFont.truetype(r'/home/jart/.fonts/Candice.ttf', fsize)
+        self.font = ImageFont.truetype(font, fsize)
         size = tuple([n + 3 for n in self.font.getsize(self.text)])
         self.img = Image.new("RGBA", size, (0, 0, 0, 0))
         cvs = ImageDraw.Draw(self.img)
         if shadow:
-            cvs.text((2, 2), self.text, font=self.font, fill='#444444')
+            cvs.text((2, 2), self.text, font=self.font, fill=(150, 150, 150, 150))
         cvs.text((1, 1), self.text, font=self.font, fill=self.color.html)
         if scew:
             self.img = self.img.transform(