PageRenderTime 42ms CodeModel.GetById 13ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/imagebuilder.php

https://bitbucket.org/udfr/uc3-udfr-ontowiki
PHP | 131 lines | 75 code | 20 blank | 36 comment | 10 complexity | 8904ee91fa6185f6e84d74d99d39276d MD5 | raw file
  1<?php
  2/*
  3============================
  4QuickCaptcha 1.0 - A bot-thwarting text-in-image web tool.
  5Copyright (c) 2006 Web 1 Marketing, Inc.
  6
  7This program is free software; you can redistribute it and/or
  8modify it under the terms of the GNU General Public License
  9as published by the Free Software Foundation; either version 2
 10of the License, or (at your option) any later version.
 11
 12This program is distributed in the hope that it will be useful,
 13but WITHOUT ANY WARRANTY; without even the implied warranty of
 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15GNU General Public License for more details.
 16============================
 17See settings.php for common settings. You shouldn't need to change
 18anything in this file.
 19============================
 20*/
 21
 22include "settings.php";
 23
 24// Keep #'s reasonable.
 25$min_thickness = max(1,$min_thickness);
 26$max_thickness = min(20,$max_thickness);
 27// Make radii into height/width
 28$min_radius *= 2;
 29$max_radius *= 2;
 30// Renormalize contrast
 31$contrast = 255 * ($contrast / 100.0);
 32$o_contrast = 1.3 * $contrast;
 33
 34$width = 15 * imagefontwidth (5);
 35$height = 2.5 * imagefontheight (5);
 36$image = imagecreatetruecolor ($width, $height);
 37imagealphablending($image, true);
 38$black = imagecolorallocatealpha($image,0,0,0,0);
 39
 40// Build the  validation string
 41$max = strlen($acceptedChars)-1;
 42$password = NULL;
 43for($i=0; $i < $stringlength; $i++) {
 44	$cnum[$i] = $acceptedChars{mt_rand(0, $max)};
 45	$password .= $cnum[$i];
 46}
 47
 48// Add string to image
 49$rotated = imagecreatetruecolor (70, 70);
 50$x = 0;
 51for ($i = 0; $i < $stringlength; $i++) {
 52	$buffer = imagecreatetruecolor (20, 20);
 53	$buffer2 = imagecreatetruecolor (40, 40);
 54	
 55	// Get a random color
 56	$red = mt_rand(0,255);
 57	$green = mt_rand(0,255);
 58	$blue = 255 - sqrt($red * $red + $green * $green);
 59	$color = imagecolorallocate ($buffer, $red, $green, $blue);
 60
 61	// Create character
 62	imagestring($buffer, 5, 0, 0, $cnum[$i], $color);
 63
 64	// Resize character
 65	imagecopyresized ($buffer2, $buffer, 0, 0, 0, 0, 25 + mt_rand(0,12), 25 + mt_rand(0,12), 20, 20);
 66
 67	// Rotate characters a little
 68	$rotated = imagerotate($buffer2, mt_rand(-25, 25),imagecolorallocatealpha($buffer2,0,0,0,0)); 
 69	imagecolortransparent ($rotated, imagecolorallocatealpha($rotated,0,0,0,0));
 70
 71	// Move characters around a little
 72	$y = mt_rand(1, 3);
 73	$x += mt_rand(2, 6); 
 74	imagecopymerge ($image, $rotated, $x, $y, 0, 0, 40, 40, 100);
 75	$x += 22;
 76
 77	imagedestroy ($buffer); 
 78	imagedestroy ($buffer2); 
 79}
 80
 81// Draw polygons
 82if ($num_polygons > 0) for ($i = 0; $i < $num_polygons; $i++) {
 83	$vertices = array (
 84		mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
 85		mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
 86		mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25)
 87	);
 88	$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
 89	imagefilledpolygon($image, $vertices, 3, $color);  
 90}
 91
 92// Draw random circles
 93if ($num_ellipses > 0) for ($i = 0; $i < $num_ellipses; $i++) {
 94	$x1 = mt_rand(0,$width);
 95	$y1 = mt_rand(0,$height);
 96	$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
 97//	$color = imagecolorallocate($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast));
 98	imagefilledellipse($image, $x1, $y1, mt_rand($min_radius,$max_radius), mt_rand($min_radius,$max_radius), $color);  
 99}
100
101// Draw random lines
102if ($num_lines > 0) for ($i = 0; $i < $num_lines; $i++) {
103	$x1 = mt_rand(-$width*0.25,$width*1.25);
104	$y1 = mt_rand(-$height*0.25,$height*1.25);
105	$x2 = mt_rand(-$width*0.25,$width*1.25);
106	$y2 = mt_rand(-$height*0.25,$height*1.25);
107	$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
108	imagesetthickness ($image, mt_rand($min_thickness,$max_thickness));
109	imageline($image, $x1, $y1, $x2, $y2 , $color);  
110}
111
112// Draw random dots
113if ($num_dots > 0) for ($i = 0; $i < $num_dots; $i++) {
114	$x1 = mt_rand(0,$width);
115	$y1 = mt_rand(0,$height);
116	$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast),$object_alpha);
117	imagesetpixel($image, $x1, $y1, $color);
118}
119
120session_start();
121//$string = new Zend_Session_Namespace('string');
122$_SESSION['string'] = $password;
123//$string = $password;
124
125header('Content-type: image/png');
126imagepng($image);
127imagedestroy($image);
128   
129    
130?> 
131