Question bout GD lib
Posted: Thu Apr 22, 2004 9:46 am
I am working on an security image creation script for my registration page which generates a 8 char string and slaps it onto an image, at this point in time it is still very easy to read, what i mean is that it could be figured out by a bot. My end goal is to split the string up into 4 bits, change the font sizes and fonts of each one, and then overlay a random transparent png image.
here is the code that im using so far
any help would be greatly appreciated, im pretty sure there is a gd function that lets you overlay an image but i cant find it.....thanks
here is the code that im using so far
Code: Select all
<?php
header("Content-type: image/png");
$letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$numbers = array('0','1','2','3','4','5','6','7','8','9');
$i = 1;
while($i < 9)
{
$rand = mt_rand(1,2);
if($rand == 1)
{
$q = mt_rand(1,26);
$char[$i] = $letters[$q];
}
if($rand == 2)
{
$q = mt_rand(1,10);
$char[$i] = $numbers[$q];
}
$i++;
}
$string = $char[1].$char[2].$char[3].$char[4].$char[5].$char[6].$char[7].$char[8];
$im = imagecreatefrompng("security.png");
$color = imagecolorallocate($im, 0, 0, 0);
$image_width = (imagesx($im) - 7.5 * strlen($string)) / 2;
$font_size = 10;
$image_height = imagesy($im) / 2 - $font_size;
imagestring($im, $font_size, $image_width, $image_height, $string, $color);
imagepng($im);
imagedestroy($im);
?>