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..
header('Content-type: image/jpg'); this means that it will be a jpg image (because our background will be jpg)Code:<?php
header('Content-type: image/jpg');
$im = imagecreatefromjpeg ("image.jpg"); It will take image.jpg for our image's backgroundCode:$im = imagecreatefromjpeg ("image.jpg");
$rand1 = rand(1,255);-Code:$rand1 = rand(1,255);
$rand2 = rand(1,255);
$rand3 = rand(1,255);
$color = imagecolorallocate($im, $rand1, $rand2, $rand3);
$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
$text = rand(1000, 9999); - This will create a random number between 1000 and 9999Code:$text = rand(1000, 9999);
$font = 'text-font.otf';
$size = 30;
$font = 'text-font.otf'; - This will be our font
$size = 30; - It will be font's size
This will put your info together to form a imageCode:imagettftext($im, $size, 0, 70, 45, $color, $font, $text);
imagejpeg($im);
imagedestroy($im);
it's that simple..
Here's the full code:
I attached this script's files alsoCode:<?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(1000, 9999);
$font = 'text-font.otf';
$size = 30;
imagettftext($im, $size, 0, 70, 45, $color, $font, $text);
imagejpeg($im);
imagedestroy($im);
?>It includes text-font.oft, image.jpg and index.php files
I'll add the part 2 for it alsotomorrow i guess
Last edited by Jaan; 04-29-2008 at 03:26 AM.
Nice tutorial. +rep.
yay.. thank you![]()
Love it, thanks
thank you![]()
You're welcome![]()
your codes are very helpfull.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks