【问题标题】:create on fly captcha image on php在php上创建即时验证码图像
【发布时间】:2015-12-11 18:16:11
【问题描述】:

我有一个即时创建 cpatcha 图像的代码,它显示图像损坏...这是代码

 $code = $this->generateCode($characters);
  /* font size will be 95% of the image height */
  $font_size = $height * 1;
  $image = imagecreate($width, $height) or die('Cannot initialize new GD       image stream');
  /* set the colours */
  $background_color = imagecolorallocate($image, 255, 255, 255);
  $text_color = imagecolorallocate($image,0, 0, 0);
  //      $text_color_2 = imagecolorallocate($image, 100, 40, 20);
  $noise_color = imagecolorallocate($image, 50, 40, 35);
  $line_color = imagecolorallocate($image, 150, 140, 135);
   //      $noise_color_2 = imagecolorallocate($image, 150, 120, 100);
  /* generate random dots in background */
  for( $i=0; $i<($width*$height)/15; $i++ ) {
     imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1,  $noise_color);
  }
  /* generate random lines in background */
  for( $i=0; $i<($width*$height)/150; $i++ ) {
     imageline($image, mt_rand(0,$width), mt_rand(0,$height),     mt_rand(0,$width), mt_rand(0,$height), $line_color);
  }
  /* create textbox and add text */
  $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
  $x = ($width - $textbox[4])/2;
  $y = ($height - $textbox[5])/2;
  imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
  /* output captcha image to browser */
  header('Content-Type: image/jpeg');
  imagejpeg($image);
  imagedestroy($image);

谁能说我的代码有什么问题?

【问题讨论】:

  • 停止了吗?加油,你可以做得更好
  • 嗯....我真的不知道这里发生了什么...它在动态创建图像...权限是问题吗?
  • 好吧,我真的不知道 stopped 在这种情况下是什么意思
  • @Dagon 图像现已被修改
  • 在文本编辑器中打开图像。检查顶部和底部是否有 php 错误

标签: php image captcha


【解决方案1】:

问题出在 BOM 字符上。我删除了它,现在它可以正常工作了。

【讨论】:

    猜你喜欢
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多