Merge branch 'master' of git.swftools.org:/home/git/swftools-internal
[swftools.git] / spec / textarea3.py
blob3e5542bce950a2f942b8873d45a1ee5493dc94e7
1 from sys import *
2 from pdflib_py import *
3 import md5
4 import Image
5 import math
7 img = Image.open("baboon.png")
8 width, height = img.size
9 img.load()
11 p = PDF_new()
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)
21 PDF_moveto(p, 0, 0)
22 PDF_lineto(p, width, 0)
23 PDF_lineto(p, width, height)
24 PDF_lineto(p, 0, height)
25 PDF_lineto(p, 0, 0)
26 PDF_fill(p)
28 PDF_setfont(p, font, 4.0)
29 i = 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:
36 continue
37 white = (l / 444.0)*5
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);
44 PDF_show(p, text[x])
45 i = i + 1
47 PDF_end_page(p)
48 PDF_close(p)
49 PDF_delete(p);