2 from pdflib_py import *
7 img = Image.open("baboon.png")
8 width, height = img.size
12 PDF_open_file(p, "textarea3.pdf")
14 PDF_set_parameter(p, "usercoordinates", "true")
16 PDF_set_info(p, "Creator", "smalltext.py")
17 PDF_begin_page(p, width, height)
18 font = PDF_load_font(p, "Courier", "host", "")
20 PDF_setrgbcolor_fill(p, 0.0, 0.0, 0.0)
22 PDF_lineto(p, width, 0)
23 PDF_lineto(p, width, height)
24 PDF_lineto(p, 0, height)
28 PDF_setfont(p, font, 4.0)
30 for y in range(height / 3):
31 text = "".join([md5.md5(str(i+j*732849)).hexdigest() for j in range(9)])
32 for x in range(width / 3):
33 r,g,b = img.getpixel((x*3, height-1-y*3))
34 l = math.sqrt(r*r+g*g+b*b)
35 if not r and not g and not b:
38 PDF_setfont(p, font, 0.5+white*7)
39 PDF_setrgbcolor_fill(p, r/l, g/l, b/l)
40 PDF_set_text_pos(p, x*3, y*3);