Jump to content

trasparent background for captcha


asmith

Recommended Posts

He guys

 

with a simple code i'm creating some captcha :

 

header("Content-Type: image/png"); 	// or image/jpg
// create the image resource

$image = ImageCreatefromgif("background.gif");

then at  last puting characters in the image : 

imagettftext($image, 30, angle, width, height, color, font, character);

 

i've tried using a transparent gif image for that , but the output background was black.

 

is there any way i could make a trasparent background for it?

 

 

 

Link to comment
Share on other sites

<?php

$png = imagecreatetruecolor(800, 600);
imagesavealpha($png, true);

$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
imagefill($png, 0, 0, $trans_colour);
   
$red = imagecolorallocate($png, 255, 0, 0);
imagettftext($png, 30, angle, width, height, $red, font, character);
   
header("Content-type: image/png");
imagepng($png);

?>

 

That *should* work. :S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.