Home  >  Q&A  >  body text

There is a problem with the final call of php to implement image verification code?

According to php how to implement image verification code content guide encapsulation verification code class capt 0.png capt1 0.png

罗梅光罗梅光874 days ago1102

reply all(8)I'll reply

  • autoload

    autoload2022-05-05 11:05:56

    //设置字体的路径 
    $font='./Daft-Font-1.ttf';
     //添加内容
      $content="hello word!"; 
      //设置字体的颜色和透明度 
      $col=imagecolorallocatealpha($image,255,255,5,1); 
      //写入文字 
      imagettftext($image,20,0,60,60,$col,realpath($font),$content);

    reply
    0
  • autoload

    autoload2022-05-05 11:04:23

    Use realpath() for the font path to convert the relative path to an absolute path

    reply
    1
  • 罗梅光

    Thanks for the reply, sir. The image is generated now, but it cannot be displayed on the page. It is only displayed on the network. Try ob_clean(); later.

    罗梅光 · 2022-05-05 12:48:07
    罗梅光

    Boss, I tried ob_clean(); but it didn’t work either. The image is now generated, but it cannot be displayed on the page. It is only displayed on the network.

    罗梅光 · 2022-05-05 13:38:13
    罗梅光

    How to separate the front-end and back-end to display the returned image on the page img.

    罗梅光 · 2022-05-05 13:38:59
    罗梅光

    Solved, thank you php.cn boss. ob_start(); imagepng($img); $image_data = ob_get_contents(); ob_end_clean(); $base64 = chunk_split(base64_encode($image_data)); return 'data:image/png;base64,' . $base64;

    罗梅光 · 2022-05-05 14:20:40
  • 罗梅光

    罗梅光2022-05-05 01:27:28

    Is the font font file not found? Where can I find the font files?

    reply
    0
  • 罗梅光

    罗梅光2022-05-05 01:23:25

    https://www.php.cn/php-ask-482565.html

    The hyperlink on the page has disappeared, please add it.

    How to implement image verification code in php

    reply
    0
  • Cancelreply