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 / 6):
31 text = "".join([md5.md5(str(i+j*732849)).hexdigest() for j in range(9)])
32 for x in range(width / 6):
33 r,g,b = img.getpixel((x*6, height-1-y*6))
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+int(white)*4)
39 r = 0.3 + 0.3 * int((r/l)*3)
40 g = 0.3 + 0.3 * int((g/l)*3)
41 b = 0.3 + 0.3 * int((b/l)*3)
42 PDF_setrgbcolor_fill(p, r, g, b)
43 PDF_set_text_pos(p, x*6, y*6);