Anonymous
Not logged in
Talk
Contributions
Create account
Log in
Publication Station
Search
Editing
Captcha
(section)
From Publication Station
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=How to generate captchas= The easies way for generating captchas is through libraries in different programming languages (Python, Javascript, PHP, etc) dedicated to this task Bellow is a list of different libraries used to produce different kind of captchas, dependencies, instructions of how to use them. ==Python== ===3D Captcha=== https://github.com/013231/3D-CAPTCHA * requires: ** [https://pypi.python.org/pypi/PIL PIL] (Python Image Library) ** [http://wiki.scipy.org/PyLab pylab] Run in the terminal: python captcha.py ==== possible changes to script ==== captcha.py allows different parameters to be changed, namely * font-face: fontPath = '/Library/Fonts/Arial.ttf' * text used in captch * image dimension and format * image color * image 3D position Here is a modified, simplified, and commented version of the captcha.py script: <source lang="python"> #!/usr/bin/env python # encoding=utf-8 from random import uniform, shuffle from cStringIO import StringIO from PIL import ImageFont, Image, ImageDraw import numpy, pylab from mpl_toolkits.mplot3d import Axes3D fontPath = '/Library/Fonts/Arial.ttf' # path to font used img_ext = 'png' # image extension. Supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff. def makeImage(text, width=400, height=200, angle=None, ext='png', rgbcolor=(1,0,1)): '''Generate a 3d CAPTCHA image. Args: text: Text in the image. width: Image width in pixel. height: Image height in pixel. angle: The angle between text and X axis. Returns: Binary data of CAPTCHA image in PNG format. ''' angle = angle if angle != None else uniform(-20, 20) try: font = ImageFont.truetype(fontPath, 24) except IOError: raise IOError( 'Font file doesn\'t exist. Please set `fontPath` correctly.') txtW, txtH = font.getsize(text) img = Image.new('L', (txtW * 3, txtH * 3), color=255) drw = ImageDraw.Draw(img) drw.text((txtW, txtH), text, font=font) fig = pylab.figure(figsize=(width/100.0, height/100.0)) ax = Axes3D(fig) X, Y = numpy.meshgrid(range(img.size[0]), range(img.size[1])) Z = 1 - numpy.asarray(img) / 255 ax.plot_wireframe(X, -Y, Z, rstride=1, cstride=1, color=( rgbcolor ) ) # "plot_wireframe" can be replace by "plot_surface" to produce a surface ax.set_zlim((-3, 3)) ax.set_xlim((txtW * 1.1, txtW * 1.9)) ax.set_ylim((-txtH * 1.9, -txtH * 1.1)) ax.set_axis_off() ax.view_init(elev=60, azim=-90 + angle) fim = StringIO() fig.savefig(fim, format=ext) binData = fim.getvalue() fim.close() return binData if __name__ == '__main__': degrees = [i*10 for i in range(0,36)] # list different degrees for n in degrees: # for loop will produce 35 different images, each in a different angle img = makeImage(text='Are you human?', width=600, height=300, angle=n, ext=img_ext, rgbcolor=(0.05,0.8,0.3) ) # Essential command: text, width, height, angle, extension, color n = str(n).rjust(3, '0') filename = 'human_{}.{}'.format(n, img_ext) print filename with open(filename, 'wb') as f: f.write(img) </source> Example output: with makeImage set to: img = makeImage(text='Are you human?', width=600, height=300, angle=n, ext=img_ext ) [[File:human_010.svg]] You can change the instruction to plot a wireframe, ax.plot_wireframe(X, -Y, Z, rstride=1, cstride=1, color=( rgbcolor ) ) for one to plot a surface: ax.plot_surface(X, -Y, Z, rstride=1, cstride=1, color=( rgbcolor ) ) the result looks like [[File:human_000.png]] [[Category:Research]]
Summary:
Please note that all contributions to Publication Station are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Publication Station:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Main navigation
Main page
Printmaking Studio
Print Studio
Dig. Publishing Studio
Namespaces
Grafiwiki
Random Page
Log in
Wiki tools
Wiki tools
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs