Welcome Guest, Not a member yet? Register   Sign In
Sending an image generated by imagepng to a view
#2

[eluser]Cristian Gilè[/eluser]
Put the captcha function in a controller:

Code:
function captcha()
{
$string = '';
  
for ($i = 0; $i < 8; $i++)
{  
     $string .= chr(rand(97, 122));  
}  

$code['rand_code'] = $string;
    
$dir = '';
    
$image = imagecreatetruecolor(170, 60);  
$black = imagecolorallocate($image, 0, 0, 0);  
$color = imagecolorallocate($image, 200, 100, 90); // red  
$white = imagecolorallocate($image, 255, 255, 255);
$lgrey = imagecolorallocate($image, 238, 238, 238);    

imagefilledrectangle($image,0,0,200,100,$lgrey);  
imagettftext($image, 30, 5, 10, 40, $color, $dir."font.ttf", $code['rand_code']);
header("Content-type: image/png");  
imagepng($image);
imagedestroy($image);
}

and load the captcha image as follow:

Code:
<img src="&lt;?php echo site_url('controller_name/captcha'); ?&gt;" alt="" />

Make sure to load the url helper and to set the dir variable in the captcha function.


Messages In This Thread
Sending an image generated by imagepng to a view - by El Forum - 06-03-2012, 07:45 AM
Sending an image generated by imagepng to a view - by El Forum - 06-03-2012, 08:24 AM
Sending an image generated by imagepng to a view - by El Forum - 06-03-2012, 08:45 AM
Sending an image generated by imagepng to a view - by El Forum - 06-03-2012, 12:22 PM
Sending an image generated by imagepng to a view - by El Forum - 06-03-2012, 02:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB