【问题标题】:how do i debug PHP Image with print?如何使用打印调试 PHP 图像?
【发布时间】:2012-08-10 11:36:56
【问题描述】:

我想用 print 调试一个 php 生成的图像算法。 问题是它不输出我打印的文本。 我怎样才能输出变量,以便我可以调试? 谢谢, 富塔诺

 public function drawPicture()
    {
        $im = imagecolorallocate ($this->picture, 255, 0, 255);
        imagettftext($this->picture, $this->fontSize , 0, 100, 100,$im , "cooperm.TTF", $this->name);



        # int ImageCopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
        //imagecopy($this->picture, $this->pika, $this->wappen['pika']['dst_x'], $this->wappen['pika']['dst_y'], 0, 0, $this->pika_size[0], $this->pika_size[1]);

        $zufall = rand(1,99999999);

        #header("Content-Type: image/jpeg");
        imagepng($this->picture);

        $this->checkFontSize();

        imagedestroy($this->picture);

        print "WHY_DOESNT_PRINT?";


    }

【问题讨论】:

  • 开启错误报告。您的脚本可能会在 print 语句之前静默失败。尝试将 print 进一步向上移动代码,甚至移动到函数的开头,以确保它被调用。
  • 脚本没有失败。我就是这样使用脚本 print '';
  • 你现在看到了什么?考虑到您注释掉了对 header 函数的调用,但您仍在调用 imagepng,您应该会在它之后看到图像源和文本
  • 我只看到图像并且在我把它放在 imagepng() 之后文本没有出现,如果我使用 imagejpeg() 代替它把文本放在右边 Oo
  • 如果您看不到图像并且文本是您在代码中的某处发送图像标题。确保您没有在代码中的其他位置发送标题图像。

标签: php image debugging


【解决方案1】:

您正在向浏览器发送 .png 图像,因此浏览器会尝试显示图像。附加文本只是被视为无效的图像数据,因此不会显示。

解决您的问题的方法是使用header() 调用将调试消息发送到您的浏览器,或者使用 Firefox+Firebug+ PHP firebug 适配器。 Firebug 与标头一起传输信息,因此在图像生成功能中是安全的。

【讨论】:

    【解决方案2】:

    使用 rorrorlog 调试您想查看的脚本点。 写入的文件可以轻松查看。

    Es:

    error_log("\r\n debug " . implode("; ", $hc), 3, "errors.log"); // in case array
    error_log("\r\n print " . $im, 3, "errors.log");
    

    【讨论】:

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