There is a problem with the final call of php to implement image verification code?
罗梅光
罗梅光 2022-05-05 01:22:00
0
8
1156

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

罗梅光
罗梅光

reply all(4)
autoload
//设置字体的路径 
$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);
autoload

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

  • reply 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.
    罗梅光 author 2022-05-05 12:48:07
  • reply 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.
    罗梅光 author 2022-05-05 13:38:13
  • reply How to separate the front-end and back-end to display the returned image on the page img.
    罗梅光 author 2022-05-05 13:38:59
  • reply 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;
    罗梅光 author 2022-05-05 14:20:40
罗梅光

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

罗梅光

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template