[PHP] Issue With GD library

From the Asset Store
This pack of sounds for monsters consists of 107 sounds, among which you can find different sounds of Attack, Death, Ste
  • Some time ago I wrote simple code in PHP to generate an image (captcha) and it works:

    Today I again run code to make some documentation to improve it in future, but there is something weird...
    Output image looks like this:
    and here is full code:
    			function MakeRandomTxt($lenght = 5){
    				$characters = '!@#$%^&*()_+0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    				$charactersLength = strlen($characters);
    				$randomString = '';
    					for ($i = 0; $i < $lenght; $i++) {
    						$randomString .= $characters[rand(0, $charactersLength - 1)];
    				return $randomString;
    		$rnd = MakeRandomTxt();	
    		$string = $rnd;
    		$font_size = rand(24, 48); 
    		$width  = 140+imagefontwidth($font_size)*strlen($string); 
    		$height = 36+imagefontheight($font_size); 
    		$img 	= imagecreate($width,$height); 
    		$bg   	= imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)); 
    		$color 	= imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)); 
    		$len 	= strlen($string); 
    		$ypos 	= 14; 
    			$xpos = 64+$i * imagefontwidth($font_size); 
    			imagechar($img, $font_size+20, $xpos, rand(2, $ypos), $string, $color); 
    			$string = substr($string, 1);    
    		header("Content-Type: image/png");
    		imagepng($img, './cp/'.$rnd.'.png'); 
    Pastebin version:
    What causing this problem?
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)