drqja5919276 2018-10-06 09:29
浏览 327

使用GD库进行验证码,不显示图像

I am using a GD library to generate captcha image. But the image is not showing up. Can you please help me with it. This is a text converted to captcha image index.php

<?php
session_start();
$_SESSION['secure']=rand(1000,9999);
?>

<img src="generate.php" />

generate.php

<?php 
session_start();
header('Content-type: image/jpeg');
$text = $_SESSION['secure'];
$font_size=30;

$image_width=200;
$image_height=40;

$image = imagecreate($image_width,$image_height );
imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);

imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text);
imagejpeg($image);

?>

These above are the two files with which I am trying to generate a captcha image. But the image is not showing up. My GD library is enabled, i have had a check on it. Any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • douqiao3453 2018-10-06 11:35
    关注

    From documentation

    Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.

    So try something like:

    $font = "/path_to_folder/font.ttf";

    imagettftext($image, $font_size, 0, 15, 30, $text_color, $font, $text);

    This work for me.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器