Jump to content

Effect for captcha image

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
I'm trying to create a capthca, I know the code that I need, I already did it in the past.
The problem is the image, I need something like this
Posted Image

but I don't know how to create this effect.
In the past for captcha images I used to put simple lines on the code, this time I'm trying something different.
I tried with imagefilter, but I don't see anything that could help me.
Which function do I have to use?

#2
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
GD doesn't have those functions.
You can manually do it. for ex:
1.get line from image
2.apply some sin or cos functions with random seed
3.store line to 2nd image
4.if image finished - output 2nd image.
OR
you can use imagemagick lib. They have like a dozen of distorting functions.Here the list

#3
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
I have NO experience with images in PHP but I saw something where you can echo out text onto images.
How about you create a image and print letters out randomly on the Y axis.
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#4
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
it's pretty easy to crack this, even if you put letters randomly - they are still letters, not distorted.

#5
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
Yeah I know that...
You could just use reCaptcha- Or you could install custom fonts.
You could try making a distorted alphabet in images and have PHP put them together.
It is quite hard to do this well....
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#6
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Not neccesary.
The only problem always be -> is it profitable to hack particular defence or not. If it is - then nothing can stop hackers.)
So you only want to make hacker spent more than he will gain.
You don't actually need an absolute defence - cause it will be like..
Posted Image

#7
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts

ghost_x47 said:

GD doesn't have those functions.
You can manually do it. for ex:
1.get line from image
2.apply some sin or cos functions with random seed
3.store line to 2nd image
4.if image finished - output 2nd image.
Thanks, I've used a solution like this and it works :)

#8
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Nice to hear that.
I never had a chance to test it.)

#9
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
I was on another PC before and I hadn't the code.
Now I'm on my PC and I can post it.
<?php
session_start();

header("Content-type: image/png");

$font = "courbi.ttf";
$image = imagecreate(200,60);

$background_color = ImageColorAllocate($image, rand(0,120), rand(0,120), rand(0,120));

$colour1 = ImageColorAllocate($image, rand(120,255), rand(120,255), rand(120,255));

imagettftext($image,26,0,30,40,$colour1,$font,$_SESSION['captcha']);
imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR);
$scale = 2;
$width = 200;
$height = 60;
$xperiod = 10;
$xamplitude = 5;
$yperiod = 12;
$yamplitude = 14;

// X-axis wave generation
$xp = $scale*$xperiod*rand(1,3);
$k = rand(0, 100);
for ($i = 0; $i < ($width*$scale); $i++) {
    imagecopy($image, $image,
        $i-1, sin($k+$i/$xp) * ($scale*$xamplitude),
        $i, 0, 1, $height*$scale);
}

// Y-axis wave generation
$k = rand(0, 100);
$yp = $scale*$yperiod*rand(1,2);
for ($i = 0; $i < ($height*$scale); $i++) {
    imagecopy($image, $image,
        sin($k+$i/$yp) * ($scale*$yamplitude), $i-1,
        0, $i, $width*$scale, 1);
}

imagepng($image);

imagedestroy($image);
?>
I hope that this can be useful to someone :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users