Esempio n. 1
0
 def create_image(self, text, filename, size=100, color=(0, 0, 0), format=None):
     font = ImageFont.truetype(self.file.get_path(), size)
     if format == 'bmp':
         image = Image.new("RGB", font.getsize(" " + text + " "), (255, 255, 255))
     else:
         image = Image.new("RGBA", font.getsize(" " + text + " "), (255, 255, 255, 0))
     ImageDraw.Draw(image).text((0, 0), " " + text + " ", font=font, fill=(color[0], color[1], color[2], 255))
     
     image = autocrop(image, (255, 255, 255, 0))
     
     if isinstance(filename, type(cStringIO.StringIO())):
         format=format or 'png'
         image.save(filename, format)
     else:
         image.save(filename, format)
Esempio n. 2
0
 def getsize(self, text, size):
     font = ImageFont.truetype(self.file.get_path(), size)
     image = Image.new("RGB", font.getsize(" " + text + " "), (255, 255, 255))
     ImageDraw.Draw(image).text((0, 0), " " + text + " ", font=font, fill=(0, 0, 0))
     image = autocrop(image, (255, 255, 255, 0))
     return image.size