Jump to content


Php Captcha and GD


2 replies to this topic

#1 Gibbons

    Young Padawan

  • Members
  • Pip
  • 182 posts
  • Gender:Male
  • Location:UK

Posted 08 December 2007 - 05:47 AM

Php Captcha and GD

I have managed to create my own php captchas using php and GD, however I was wondering how to go about changing the orientation of the text. Does anyone know what to do?

I want to produce something similar to the curving shown below:
Attached File  captcha.jpg   23.69K   47 downloads

Thanks very much.

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 08 December 2007 - 10:06 PM

It takes some trigonometry, but it is possible.
I have this function I've take from somewhere and adapted (I would cite if I could) that does this.

function wave_area($img, $x, $y, $width, $height, $amplitude = 10, $period = 10){
	// Make a copy of the image twice the size
	$height2 = $height * 2;
	$width2 = $width * 2;
	$img2 = imagecreatetruecolor($width2, $height2);
	imagecopyresampled($img2, $img, 0, 0, $x, $y, $width2, $height2, $width, $height);
	if($period == 0) $period = 1;
	// Wave it
	for($i = 0; $i < ($width2); $i += 2)
		imagecopy($img2, $img2, $x + $i - 2, $y + sin($i / $period) * $amplitude, $x + $i, $y, 2, $height2);
	// Resample it down again
	imagecopyresampled($img, $img2, $x, $y, 0, 0, $width, $height, $width2, $height2);
	imagedestroy($img2);
}

I honestly cannot explain the trig parts, but other than that is is just basically moving the pixels around on a copied image.

This function waves a certain part of the image. To wave the entire image, you can call it like this.
wave_area($img, 0, 0, imagesx($img), imagesy($img), 10, 10);

Have fun adjusting the amplitude and period until you get a good image; or even randomize them.

Edited by Demonslay, 08 December 2007 - 10:07 PM.


#3 Gibbons

    Young Padawan

  • Members
  • Pip
  • 182 posts
  • Gender:Male
  • Location:UK

Posted 12 December 2007 - 10:22 AM

I appreciate that reply very much. I will attempt to implement it. :P :biggrin: :biggrin:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users