aboutsummaryrefslogtreecommitdiff
path: root/captcha.php
blob: 085641c797d70f3e457063eada3aad36e91bde2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
 * Elgg captcha plugin graphics file generator
 * 
 * @package ElggCaptcha
 */

$token = get_input('captcha_token');

// 	Output captcha
if ($token) { 
	// Set correct header
	header("Content-type: image/jpeg");

	// Generate captcha
	$captcha = captcha_generate_captcha($token);

	// Pick a random background image
	$n = rand(1, elgg_get_config('captcha_num_bg'));
	$image = imagecreatefromjpeg(elgg_get_plugins_path() . "captcha/backgrounds/bg$n.jpg");	

	// Create a colour (black so its not a simple matter of masking out one colour and ocring the rest)
	$colour = imagecolorallocate($image, 0,0,0);

	// Write captcha to image
	//imagestring($image, 5, 30, 4, $captcha, $black);
	imagettftext($image, 30, 0, 10, 30, $colour, elgg_get_plugins_path() . "captcha/fonts/1.ttf", $captcha);

	// Output image
	imagejpeg($image);

	// Free memory
	imagedestroy($image);
}