View Single Post
  #1 (permalink)  
Old 04-28-2008, 04:54 PM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Moderator">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 815
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Creation of captcha

Hey there!

I was thinking.. there are many users who have asked from me.. how to create a captcha or that image where are those random numbers or letters.. so i thought i'll make one..

PHP Code:
<?php
header
('Content-type: image/jpg');
header('Content-type: image/jpg'); this means that it will be a jpg image (because our background will be jpg)

PHP Code:
$im imagecreatefromjpeg ("image.jpg"); 
$im = imagecreatefromjpeg ("image.jpg"); It will take image.jpg for our image's background
PHP Code:
$rand1 rand(1,255);
$rand2 rand(1,255);
$rand3 rand(1,255);
$color imagecolorallocate($im$rand1$rand2$rand3); 
$rand1 = rand(1,255);-
$rand2 = rand(1,255);- - Those variables will create a random number from 1 to 255 so we will have a random color for our text
$rand3 = rand(1,255);-
$color = imagecolorallocate($im, $rand1, $rand2, $rand3); - This will create a color for our text

PHP Code:
$text rand(10009999);
$font 'text-font.otf';
$size 30
$text = rand(1000, 9999); - This will create a random number between 1000 and 9999
$font = 'text-font.otf'; - This will be our font
$size = 30; - It will be font's size

PHP Code:
imagettftext($im$size07045$color$font$text);
imagejpeg($im);
imagedestroy($im); 
This will put your info together to form a image it's that simple..

Here's the full code:

PHP Code:
<?php
header
('Content-type: image/jpg');
$im imagecreatefromjpeg ("image.jpg");
$rand1 rand(1,255);
$rand2 rand(1,255);
$rand3 rand(1,255);
$color imagecolorallocate($im$rand1$rand2$rand3);
$text rand(10009999);
$font 'text-font.otf';
$size 30;
imagettftext($im$size07045$color$font$text);
imagejpeg($im);
imagedestroy($im);
?>
I attached this script's files also It includes text-font.oft, image.jpg and index.php files

I'll add the part 2 for it also tomorrow i guess
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
__________________


Cheap & Professional Web Design | Need help? Send a PM

Last edited by Jaan; 04-29-2008 at 05:26 AM.
Reply With Quote

Sponsored Links