Subversion Repositories SmartDukaan

Rev

Rev 11128 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11128 Rev 11272
Line 39... Line 39...
39
 */
39
 */
40
if ( ! function_exists('create_captcha'))
40
if ( ! function_exists('create_captcha'))
41
{
41
{
42
	function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
42
	function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
43
	{
43
	{
-
 
44
		ob_start();
44
		$defaults = array('word'      => '',    'word_length' => 5,
45
		$defaults = array('word'      => '',    'word_length' => 5,
45
                  'img_path'  => '',    'img_url'     => '',
46
                  'img_path'  => '',    'img_url'     => '',
46
                  'img_width' => '150', 'img_height'  => '30',
47
                  'img_width' => '150', 'img_height'  => '30',
47
                  'font_path' => '',    'expiration'  => 7200);
48
                  'font_path' => '',    'expiration'  => 7200);
48
 
49
 
Line 191... Line 192...
191
 
192
 
192
		$use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;
193
		$use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;
193
 
194
 
194
		if ($use_font == FALSE)
195
		if ($use_font == FALSE)
195
		{
196
		{
196
			$font_size = 14;
197
			$font_size = 30;
197
			$x = rand(0, $img_width/($length/3));
198
			$x = rand(0, $img_width/($length/3));
198
			$y = 0;
199
			$y = 0;
199
		}
200
		}
200
		else
201
		else
201
		{
202
		{
Line 207... Line 208...
207
		for ($i = 0; $i < strlen($word); $i++)
208
		for ($i = 0; $i < strlen($word); $i++)
208
		{
209
		{
209
			if ($use_font == FALSE)
210
			if ($use_font == FALSE)
210
			{
211
			{
211
				$y = rand(0 , $img_height/2);
212
				$y = rand(0 , $img_height/2);
212
				imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color);
213
				imagettftext($im, $font_size, $x, $y, substr($word, $i, 1), $text_color);
213
				$x += ($font_size*2);
214
				$x += ($font_size*2);
214
			}
215
			}
215
			else
216
			else
216
			{
217
			{
217
				$y = rand($img_height/2, $img_height-3);
218
				$y = rand($img_height/2, $img_height-3);
Line 230... Line 231...
230
		// -----------------------------------
231
		// -----------------------------------
231
		//  Generate the image
232
		//  Generate the image
232
		// -----------------------------------
233
		// -----------------------------------
233
 
234
 
234
		$img_name = $now.'.png';
235
		$img_name = $now.'.png';
235
 
236
		
236
		imagepng($im, $img_path.$img_name);
237
	//var_dump(imagepng($im, $img_path.$img_name));
237
 
238
		
-
 
239
		//var_dump(($im));
-
 
240
		ob_start();
-
 
241
		imagepng($im);
-
 
242
		// Capture the output
-
 
243
		$imagedata = ob_get_contents();
-
 
244
		// Clear the output buffer
-
 
245
		ob_end_clean();
238
		$img = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />";
246
		$img = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />";
239
 
-
 
240
		ImageDestroy($im);
247
		ImageDestroy($im);
241
 
-
 
-
 
248
		ob_end_clean();
-
 
249
		//echo '<img src="data:image/png;base64,'.base64_encode($image).'" />';
242
		return array('word' => $word, 'time' => $now, 'image' => $img, 'name' => $img_name);
250
		return array('word' => $word, 'time' => $now, 'name' => $img_name, 'imagedata' => base64_encode($imagedata));
243
	}
251
	}
244
}
252
}
245
 
253
 
246
// ------------------------------------------------------------------------
254
// ------------------------------------------------------------------------
247
 
255