Jump to content

Problems with a create text on image code


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 post
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 post
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 post
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 post
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 post
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 post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...