Jump to content

How do I modify this captcha?


izbryte

Recommended Posts

I want to make it bigger with a bigger red background and a larger font. I want to center the font too in the middle of the box. I don't know how to do it. Can you help?

Here's the code:

<?php

session_start();



$RandomStr = md5(microtime());// md5 to generate the random string



$ResultStr = substr($RandomStr,0,5);//trim 5 digit 



$NewImage =imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground 



$LineColor = imagecolorallocate($NewImage,233,239,239);//line color 

$TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white



imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image 

imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image 



imagestring($NewImage, 10, 20, 8, $ResultStr, $TextColor);// Draw a random string horizontally 



$_SESSION['key'] = $ResultStr;// carry the data through session



header("Content-type: image/jpeg");// out out the image 



imagejpeg($NewImage);//Output image to browser 



?>

Link to comment
Share on other sites

Seems pretty straighforward, if you read the documentation for the functions being called.  You might notice for example, that this technique starts with an existing image and then adds to it.  So if you modify that original image, you will already have modified the resultant image. 

 

$NewImage =imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground

 

 

 

Link to comment
Share on other sites

The text is written using the imagestring($NewImage, 10, 20, 8, $ResultStr, $TextColor);//  Line.

I'm not sure why this works, because the 2nd param, is suppossed to indicate the Font.  Theoretically, making 10 something bigger would pick a bigger font, but it's not indicated in the manual that even a param of 10 is supported.

 

Centering is tricky, you'd have to do a bit of math using the imagefontwidth() function.  Theoretically, this value times the number of characters being added onto the image, would allow you to figure out where to start printing (x,y), by getting the 1/2 way point of the image, and subtracting 1/2 of the length of the string from that number (to get the X coord).  Notice that currently the x,y values are hardcoded as 20,8, so you'd need to make those into variables.

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.