image code generator in php

Discussion in 'PHP' started by hulkrana, May 15, 2007.

  1. #1
    hello friends,

    please tel me how to generate php code of image code generation. In need it urgently.
    thanks
     
    hulkrana, May 15, 2007 IP
  2. technoguy

    technoguy Notable Member

    Messages:
    4,385
    Likes Received:
    308
    Best Answers:
    0
    Trophy Points:
    205
    #2
    Image generation? Do you mean image verification? Please provide more details
     
    technoguy, May 15, 2007 IP
  3. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #3
    i think you are talking about captcha images.you can use lots of open source scripts from internet.just give a search and you will get a lot of links for image validation using captcha
     
    coderbari, May 15, 2007 IP
  4. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    xooMan, May 18, 2007 IP
  5. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Here is a code i used long ago to create captcha image
    <?php
    	function random_color($im, $min, $max)
    	{
    		return imagecolorallocate($im, mt_rand($min, $max), mt_rand($min, $max), mt_rand($min, $max));
    	}
    
    	function random_ellipse($im, $min_x, $max_x, $min_y, $max_y, $w, $h) {
    		$col = random_color($im, 220, 250);
    		$x = mt_rand($min_x, $max_x);
    		$y = mt_rand($min_y, $max_y);
    		imageellipse($im, $x, $y, $w, $h, $col);
    		imageellipse($im, $x+1, $y+1, $w, $h, $col);
    	}
    
    	$im_width = 160;
    	$im_height = 40;
    	$font = 'font.ttf';
    	$font_size = 12;
    
    	$im = imagecreate($im_width, $im_height);
    	imagecolorallocate($im, 252, 252, 252);
    
    	random_ellipse($im, 5, 20, 5, 20, 110, 30);
    	random_ellipse($im, 100, 120, 5, 20, 110, 40);
    	random_ellipse($im, 80, 100, 30, 50, 140, 50);
    
    	$chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
    	$max = strlen($chars) - 1;
    	$num = "";
    
    	for($i=0; $i<5; $i++)
    	{
    		$char = $chars{mt_rand(0, $max)};
    		$rotation = ($i % 2) ? -6 : 6;
    		imagettftext($im, $font_size, $rotation, $i * 26 + 20, 26,random_color($im, 50, 240), $font, $char);
    		$num .= $char;
    	}
    	
    	$black = imagecolorallocate($im, 0, 0, 0);
    	imagerectangle($im, 0, 0, $im_width-1, $im_height-1, $black);
    	
    	setcookie("num", md5($num), time()+600);
    
    	header('Content-type: image/png');
    	imagepng($im);
    	imagedestroy($im);
    
    ?>
    Code (php):
    Of course you'll need to upload a font file and replace font.tff with it.
    And for verification
    if (md5(strtoupper($_POST['vimg'])) != $_COOKIE['num']){echo "Invalid Image Verification Code";}
    Code (php):
    Edit: It uses cookies. I could create you one to use sessions.
     
    Felu, May 18, 2007 IP
  6. infoway

    infoway Guest

    Messages:
    145
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try with GD library function.

    Or you can search at hotscripts.com for image verification script for free.

    thanx
     
    infoway, May 18, 2007 IP