parent
002930f59a
commit
f66635a6a4
@ -0,0 +1 @@
|
|||||||
|
Jaki is the best.
|
@ -0,0 +1,52 @@
|
|||||||
|
#Created by Justin Healy
|
||||||
|
#Based on logic from jsheperd from https://stackoverflow.com/a/27753869/190597
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import string
|
||||||
|
from PIL import Image
|
||||||
|
from PIL import ImageFont
|
||||||
|
from PIL import ImageDraw
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def char_to_pixels(text, path, fontsize):
|
||||||
|
|
||||||
|
font = ImageFont.truetype(path, fontsize)
|
||||||
|
w, h = font.getsize(text)
|
||||||
|
image = Image.new('L', (w, h), 1)
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
draw.text((0, 0), text, font=font)
|
||||||
|
arr = np.asarray(image)
|
||||||
|
arr = np.where(arr, 0, 1)
|
||||||
|
arr = arr[(arr != 0).any(axis=1)]
|
||||||
|
return arr
|
||||||
|
|
||||||
|
def display(arr):
|
||||||
|
result = np.where(arr, '#', ' ')
|
||||||
|
#print("This gives an Array of Arrays, where reach contained Array is a row")
|
||||||
|
#print(result)
|
||||||
|
#print()
|
||||||
|
print('\n'.join([''.join(row) for row in result]))
|
||||||
|
|
||||||
|
#I have used static coding successfully, now to set this as more reusable declarations rather than hard coding.
|
||||||
|
#Single Source to change for everything
|
||||||
|
#Read from file?
|
||||||
|
fileName = "/home/pi/Documents/pilReadTest"
|
||||||
|
pullFile = open(fileName,"r")
|
||||||
|
someString = pullFile.read()
|
||||||
|
#Font Path?
|
||||||
|
fontPath = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
|
||||||
|
#font Size?
|
||||||
|
fontSize = 12
|
||||||
|
#print("This was what was found in the File: "+str(someString))
|
||||||
|
#print()
|
||||||
|
#print("Now putting each letter of the found string through the PIL Image Module")
|
||||||
|
#print()
|
||||||
|
for c in someString:
|
||||||
|
arr = char_to_pixels(c,fontPath,fontSize)
|
||||||
|
#print()
|
||||||
|
#This is the grid size results (w,h)
|
||||||
|
#print(arr.shape)
|
||||||
|
#print()
|
||||||
|
#print("This is the converted values of the AofAs, for each ROW in Result, the end product")
|
||||||
|
display(arr)
|
||||||
|
print()
|
Loading…
Reference in new issue