ImagickDraw Rectangle - 图像无法显示错误

ImagickDraw Rectangle - image cannot be displayed error

我有两个站点(同一台服务器),其中一个简单的矩形是使用 ImagickDraw 绘制的,它在一个上工作正常,在第二个上失败并出现错误 -

The image "http://site_name/imagick/img?method=placeholder&params=258,150" cannot be displayed because it contains error.

基本上,代码的作用是从 url 中获取 methodparams(高度和宽度)并绘制图像。

$params = explode(",", $_GET["params"]);
$width = (int) $params[0]; //258
$height = (int) $params[1]; //150

if ($method == "placeholder") { //This is true $method is set to placeholder
  $image = new Imagick();
  $image->newImage($width, $height, "#707070");
  $image->setImageFormat("png");

  $x = 0;
  $y = 0;
  $size = 40;
  $draw = new ImagickDraw();

  while ($y < $height) {
    $draw->setFillColor("#808080");

    $points = array(
      array("x" => $x, "y" => $y),
      array("x" => $x + $size, "y" => $y),
      array("x" => $x + $size * 2, "y" => $y + $size),
      array("x" => $x + $size * 2, "y" => $y + $size * 2),
    );
    $draw->polygon($points);

    $points = array(
      array("x" => $x, "y" => $y + $size),
      array("x" => $x + $size, "y" => $y + $size * 2),
      array("x" => $x, "y" => $y + $size * 2),
    );
    $draw->polygon($points);

    $x += $size * 2;
    if ($x > $width) {
      $x = 0;
      $y += $size * 2;
    }
  }

  $draw->setFillColor("#B0B0B0");
  $draw->setFontSize($width / 5);
  $draw->setFontWeight(800);
  $draw->setGravity(Imagick::GRAVITY_CENTER);
  $draw->annotation(0, 0, $width . " x " . $height);

  $image->drawImage($draw);

  header("Content-type: image/png");
  echo $image;
}

我在 header 之前检查了缓冲区,它是空的,也尝试过 ob_clean() - 仍然不起作用。

检查了文件中的 white-spaces,因为我发现它会影响图像文件 - 但不存在 white-space。

有什么想法可以跟踪错误吗?

确实是白色的space但是不在同一个文件中(怪怪的怪怪的)

使用 -

检查项目中包含的所有 php 个文件
include_once('file_name.php');

在多个文件中,有一个这样的文件(包含 db_namebase url 等的设置文件)在 <?php 标记之前有一个 space。因此,如果有人遇到此错误,请确保所有 php 文件都是白色的 space 免费的。它弄乱了生成的png图像。