PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to write text on image onfly in php?

 October 11, 2022     gd, gd2, image, php     No comments   

Issue

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


Solution

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/



Answered By - mantigatos
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing