I'm trying to create a table (width = 190px, height = 128px) that is filled with some text and save that as an image. I managed to do that both with matplotlib and by simply generating a HTML table however with both methods I run to the same problem the text gets "compressed" and is blurry. Blurry letters
I would like to generate a pic like this 32x16 pic hand drawn in paint. What would be the best way to achieve this. At the moment I am using python to generate the HTML table and then I am saving it using the html2image library. The table needs to be generated programmatically though. Furthermore I tried to sample only some of the pixels above a threshold but then the text is even worse. The image can be saved as .pgn, .jpg or .bmp Any advice is appreciated! The code below is how I am generating and saving the table ATM.
def printTable(data):
htmlTable = ""
htmlTable += '<table>'
htmlTable += '<tr>'
htmlTable += '<td>%s</td>'% "NAME"
htmlTable += '<td>%s</td>'% "LAST NAME"
htmlTable += '<td>%s</td>'% "PASSWORD"
htmlTable += '<td>%s</td>'% "USERNAME"
htmlTable+= '</tr>'
for element in data.itertuples():
htmlTable += '<tr>'
htmlTable += ('<td>%s</td>'% element.NAME)
htmlTable += ('<td>%s</td>'% element.LAST NAME)
htmlTable += ('<td>%s</td>'% element.PASSWORD)
htmlTable += ('<td>%s</td>'% element.USERNAME)
htmlTable += '</tr>'
htmlTable += '</table>'
return htmlTable
tableString = printTable(df1)
print(tableString)
from html2image import Html2Image
hti = Html2Image(size=(190, 128))
#hti = Html2Image()
html = tableString
css = "\
@font-face {\
font-family: myFirstFont;\
src: url(Dogica Pixel Regular.ttf);\
}\
table, th, td{ \
border:1px solid red; \
border-collapse: collapse; \
background-color: black; \
color:red \
}\
table{ \
widht: 190px;\
font-size: 8px;\
font-family:myFirstFont\
}\
"
hti.screenshot(html_str=html, css_str=css, save_as='htmlTable.png')
P.S. I really hope hand drawing every pixel on a canvas isn't the only solution xd.