0

I want to make an image "onfly" with some text. Is it possible with php? I am trying with this one but no output is coming can anyone watch my code please?

function createCaptcha($string){
    $image = PATH_DIR . "blueprint/images/bg6.png";
    $text_vertical_position = 97;
    $font_size = 15;
    $color = '32a53d';
    Header ("Content-type: image/png");
    $color = convert_to_rgb($color);
    $info = GetImageSize($image);
    $width = $info[0];
    $height = $info[1];


    if (preg_match("/.gif/", $image)) {
        $image = imageCreateFromGif($image);
    } elseif (preg_match("/.png/", $image)) {
        $image = imageCreateFromPng($image);
    } elseif (preg_match("/.jpg/", $image)) {
        $image = imageCreateFromJpeg($image);
    } elseif (preg_match("/.jpeg/", $image)) {
        $image = imageCreateFromJpeg($image);
    }

    $imgcolor = ImageColorAllocate ($image, $color[0], $color[1], $color[2] );
    imagettftext($image, $font_size, 0, $start_length, $text_vertical_position,
                 $imgcolor, $font , $text);
    ImagePNG ($image);
    ImageDestroy ($image);
}

I am using codeigniter to make it.

Thank You

Mattias
  • 9,211
  • 3
  • 42
  • 42
danny
  • 465
  • 3
  • 8
  • 18

1 Answers1

1

It seems you made a mistake in parameter of the function: $string not $text

 imagettftext($image, $font_size, 0, $start_length, $text_vertical_position,
      $imgcolor, $font, $string);

PS. If you make captcha - it would not reliable without any additional distortion of the image.

Why not to use ready-made solutions?

http://www.phpcaptcha.org/

http://www.captcha.ru/kcaptcha/

mantigatos
  • 296
  • 1
  • 5