Question bout GD lib

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Question bout GD lib

Post by dull1554 »

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

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);
?>
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
Post Reply