Jump to content

Problems with a create text on image code


Kristian_C

Recommended Posts

Well here's the code :

<?$tittel		 = $_GET['tittel'];$font_storrelse = 12;$tekst_farge	= imagecolorallocate (99, 99, 99);$bilde		  = imagecreatefromjpeg("images/button_01.jpg");imagestring($bilde, $font_storrelse, rand(5,5), rand(3,3), $tittel, $tekst_farge);header("Content-type: image/jpg");imagepng($bilde,'',80);?>

Think the code is pretty wrong :).. So help pleace? :)..The reason for text create on image is becouse i want to use php buttons =)...-Kristian_C

Link to comment
Share on other sites

Hi.. try to look at ur code: in that u r creating jpeg image and use png in header do the "imagejpeg($bilde,'',80);" instead of ur last line..

<?$tittel		 = $_GET['tittel'];$font_storrelse = 12;$tekst_farge	= imagecolorallocate (99, 99, 99);$bilde		  = imagecreatefromjpeg("images/button_01.jpg");imagestring($bilde, $font_storrelse, rand(5,5), rand(3,3), $tittel, $tekst_farge);header("Content-type: image/jpg");imagepng($bilde,'',80);?>

Regards,Vijay

Link to comment
Share on other sites

Guest westmatrix99

Use this:This part goes right at the top of page.

<?php session_start();if(isset($_POST['subbutton'])){ //name your button for this to workif ($_POST['vercode'] != $_SESSION['vercode'] OR $_SESSION['vercode']=='')  {$error = '<strong><font color="#FF0000">Incorrect verification code.</font></strong><br>';//add the above error message next to the vercode textbox with the echo tag.} else {//process the form or whatever you want}}?>

The captcha.php page:

<?session_start();$text = rand(10000,99999);$_SESSION["vercode"] = $text;$height = 25;$width = 65;$image_p = imagecreate($width, $height);$black = imagecolorallocate($image_p, 0, 0, 0);$white = imagecolorallocate($image_p, 255, 255, 255);$font_size = 14; imagestring($image_p, $font_size, 5, 5, $text, $white);imagejpeg($image_p, null, 80);?>

Save it as captcha.php and call it in an image tag on your page like this:

<img src="captcha.php" id="image"alt="Code" />

If you are using this for captcha purposes.CheersWest================

Well here's the code :
<?$tittel		 = $_GET['tittel'];$font_storrelse = 12;$tekst_farge	= imagecolorallocate (99, 99, 99);$bilde		  = imagecreatefromjpeg("images/button_01.jpg");imagestring($bilde, $font_storrelse, rand(5,5), rand(3,3), $tittel, $tekst_farge);header("Content-type: image/jpg");imagepng($bilde,'',80);?>

Think the code is pretty wrong :).. So help pleace? :)..The reason for text create on image is becouse i want to use php buttons =)...-Kristian_C

Link to comment
Share on other sites

Sorry westmatrix99, but it aint a vertification thing im trying to create, its a button :)... ok, Vijay, now ive changed the last line to jpeg, but my text dont show :s... tried different color codes but dont work :s

<?php$tittel		 = $_GET['tittel'];$font_storrelse = 12;$tekst_farge	= imagecolorallocate (ff, ff, ff);$bilde		  = imagecreatefromjpeg("images/button_01.jpg");imagestring($bilde, $font_storrelse, rand(5,5), rand(3,3), $tittel, $tekst_farge);header("Content-type: image/jpg");imagejpeg($bilde,'',80);?>

Link to comment
Share on other sites

You use the functions to generate or modify images only. A captcha is just an image. You can read through the image reference, look through the function list to get an idea about what it can do, click on whatever functions you want to learn more about.http://www.php.net/manual/en/ref.image.php

Link to comment
Share on other sites

You start with something like imagecreatetruecolor or imagecreatefrompng and go from there, there are functions you can use to set colors, draw lines or shapes, write text, etc, it just depends what you want to do. Check the reference for the imagecreate functions to see that, or check something like the imagestring reference to get an example of how to create an image and write text in it.http://www.php.net/manual/en/function.imagestring.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...