quick search:
 

automatic image generation

Submitted by: Deltax
Last Edited: 2005-11-17

Category: Security

Average rating is: 0.0 out of 5 (0 ratings)

Description:
This code produces an automatic generated image with numbers, which can be used for login/join scripts.

Source (Text):
\documentclass{minimal}
\begin{document}
<dtml-let seed=xtr>
<dtml-call expr=_.random.seed(int(seed))>
</dtml-let>
Tik de volgende getallen over in het hokje:
$ <dtml-in expr="_.range(5)">
<dtml-try>
 |<dtml-var expr=_.random.randint(0,90)> |
<dtml-except>
</dtml-try>
</dtml-in>
$
\end{document}
----------Diff for DTMLTeX.py----------------------------------------
65c65
<     defaultfilter = "pdf"
---
>     defaultfilter = "png"
69c69
<                'ps': {'ct':'application/ps',
---
>                'ps': {'ct':'application/ps',
72c72,76
<                       'ext':'ps'}}
---
>                       'ext':'ps'},
>                'png': {'ct':'image/png',
>                       'path': os.path.join(os.path.split(__file__)[0],
>                                            'genpnglatex'),
>                       'ext':'png'}}



---------Code for genpnglatex( put it in the DTMLTeX directory)--------
#!/bin/sh
# This script generates Png from latex incorporated into one command

base=`basename $2 .tex`
latex $@ && dvipng -o $base.png $base.dvi

ERROR: EOF in multi-line statement


Explanation:
It generates a png image with 5 numbers in it, which are generated by the
random module of python. The DTMLTeX (0.5.2) product makes with help from dvipng a
a png-image from it. Because you use a known seed, you can easily make
a login/join script. which requires the user to type the numbers over to protect
your site against bots. It is also nice, you can make png images with latex.


Comments:

Another way via external method by axxs - 2005-11-17
#!/usr/bin/env python

import Image, ImageDraw, ImageFont, random

def randomString():
    ascii = 'abcdefghijkmnpqrstuvwxyz123456789'
    return ''.join(random.sample(ascii, 5))

def verify():
    image = Image.new('RGB', (115, 40), (39, 36, 81))
    font = ImageFont.truetype('/var/lib/defoma/gs.d/dirs/fonts/VeraSeBd.ttf', 25)
    draw = ImageDraw.Draw(image)
    draw.text((5, 5), randomString(), font = font, fill = (153, 204, 0))
    #image.save('verify.jpg')
    image.show()

if __name__ == '__main__': verify()