Zend - The PHP Company




Algorithms

Add Code


Turing Number Generate  

Type: code fragment
Added by: saneesh
Entered: 01/09/2004
Last modified: 09/12/2003
Rating: - (fewer than 3 votes)
Views: 6885
Its Generating a simple Turing Number with background image,place the mouse over the image if the number is not clear


<?
/*
 *      Requirement : Uncomment 'extension=php_gd2.dll' in PHP.INI [Remove the semi-colon(;)]
 *      Usage       : Generating Turing Number,place the mouse over the image if the number is not clear
 *      EMail       : saneeshkv@yahoo.com
 */
    
header("Content-type: image/png");
    
$new_string="";
    echo 
"<html>
            <head>
                <title>
                    Verification
                </title>
            </head>
            <body>"
;
    
$im ImageCreate(58,22);   // ImageCreate(X,Y)
    //$im     = imagecreatefrompng("San.png");  // Also can set image as background
    
function make_seed()
    {
           list(
$usec$sec) = explode(' 'microtime());
           return (float) 
$sec + ((float) $usec 100000);
    }
    
srand(make_seed());

    
$string md5(rand(0,9999));
    
$new_string strtoupper(substr($stringrand(0,26), 5));

    
$color_back ImageColorAllocate($im255,255,255);   // ImageColorAllocate(Image Resource,R,G,B)
    
ImageFill($im00$color_back); // Image's Background Color.

    //$text_color = ImageColorAllocate($im, rand(0,225), rand(0,225), rand(0,225));
    
$text_color ImageColorAllocate($im225,0,0);
    
//    imagestring ($im,5,5,3, $new_string , $text_color); 
    
ImageTTFText ($im100815$text_color"Verdana.ttf"$new_string);

    
//$color_line = ImageColorAllocate($im, 225,190,102);
    
$color_line ImageColorAllocate($imrand(0,225), rand(0,225), rand(0,225));
    for(
$i=0;$i<25;$i+=5)
        
imageline ($im,0,$i,54,$i,$color_line);   //  Horizondal Lines

    
for($i=0;$i<60;$i+=5)
        
imageline ($im,$i,0,$i,22,$color_line);   //  Vertical Lines

    
ImagePNG($im"verify.png");   // Create file named 'verify.png'
    
    
$new_spaced_string "";
    for(
$i=0;$i<strlen($new_string);$i++)   
        
$new_spaced_string .= " ".$new_string[$i]." ";

    print 
'<img src="verify.png" border=0 alt = "'.$new_spaced_string.'">';

    
ImageDestroy($im);

    echo 
"
            </body>
        </html>"
;
exit;

/*
   header("Content-type: image/png");
   $string = "1234";//$_GET['text'];
   $im     = imagecreatefrompng("san3.png");
   $orange = imagecolorallocate($im, 220, 210, 60);
   $px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
   imagestring($im, 3, $px, 9, $string, $orange);
   imagepng($im);
   imagedestroy($im);
    print '
        <table>
            <tr>
                <td align = center><img src = "san3.png"></td>
            </tr>
        </table>';
        */

    
header ("Content-type: image/png");
    
imagepng (LoadPNG ("./san3.png"));



    function 
LoadPNG ($imgname)
    {
       
$im = @imagecreatefrompng ($imgname); 
       if (!
$im)
       {
            
$im  imagecreate (15030);
            
$bgc imagecolorallocate ($im255255255);
            
$tc  imagecolorallocate ($im000);
            
imagefilledrectangle ($im0015030$bgc);

            
//$text_color = imagecolorallocate ($im, 233, 14, 91);
            //imagestring ($im, 1, 5, 5,  "A Simple Text String", $text_color);

            
imagestring ($im155"Error loading $imgname"$tc);
       }
       return 
$im;
    }

exit;
?>

<html>
<head>
</head>
<body>
<?php

//$pic=ImageCreate(150,30);
$pic imagecreatefrompng ("san3.png");

//$col1=ImageColorAllocate($pic,200,200,200);

$col2=ImageColorAllocate($pic,233,214,255);

$text_color imagecolorallocate ($pic2331491);
imagestring ($pic155,  "A Simple Text String"$text_color);

//ImageFilledRectangle($pic,1,1,100,100,$col2);

ImagePNG($pic,"pic.png");
ImageDestroy($pic);
?>
<img src="pic.png" border=0>
</body>
</html>



Usage Example




Rate This Script





Search



This Category All Categories