0

ImageFilledArcを使用して2ストロークエンジンのタイミング図を描く複雑なPHPがあります。php 5.2で何年も機能しましたが、私のISPはサーバーをPHP 5.3にアップグレードし、アークはレンダリングされなくなりました。下の画像は、何が起こり、何が期待されたかを示しています。

ここに画像の説明を入力してください

テストでは、関数が'style'のすべての値にFAIL(ゼロ)を返していることが示されています。実験では、ImageFilledRectangleが期待どおりに機能することが示されています(プログラムに挿入されたコードにより、同じターゲットGDイメージインスタンスとカラー値が使用されます)。

Web検索では、PHP遷移ドキュメント内のグラフィック関数への変更についての言及や、この関数に問題がある他の人を見つけることができませんでした。グラフィックを描画するコードを以下に示します。それを呼び出すコードはそうではありませんが、引数なしでページを呼び出すことでテストできます。

<?php
/*
 * Creats a PNG image of the MBI CAD standard timing 2-stroke diagram.
 *
 * Created on Aug 10, 2007 by Ronald A Chernich, Brisbane, Australia.
 * This work is licensed under the Creative Commons
 * Attribution-Noncommercial-Share Alike 3.0 license.
 * See: http://creativecommons.org/licenses/by-nc-sa/3.0
 *
 * 2007-08-08 1.0   First version
 * 2007-08-13 1.1   Add FRV labeling adjustment
 * 2007-08-15 1.2   Add SPI capability and blow-down
 * 2007-08-15 1.2.1 Revise SPI representation to Inlet side of graph
 * 2007-08-25 1.2.2 SPI and inlet labels overlapped in some cases. Fixed.
 */

  $eo = $_GET['eo'];
  $to = $_GET['to'];
  $ic = $_GET['ic'];
  $id = $_GET['id'];
  $nm = $_GET['nm'];
  $spi = $_GET['spi'];

  // Test data for development
  if (empty($nm)) {
    $nm = 'Test';
    $eo = 108;
    $to = 123;
    $ic = 15;
    $id = 140;
  }

  $graph = new TimingDiagram($nm, $eo, $to, $ic, $id, $spi);
  $graph->render();

/**
 * Class to render image
 */
class TimingDiagram
{
    var $WIDTH = 420;
    var $HEIGHT = 420;
    var $YMARGIN = 30;
    var $XMIN = 2;
    var $YMIN = 2;

    var $BG_COLOR;
    var $IN_COLOR;
    var $TR_COLOR;
    var $EX_COLOR;
    var $LAP_COLOR;
    var $AXIS_COLOR;
    var $TITLE_COLOR;

    var $image;

    var $eo;
    var $to;
    var $ic;
    var $id;
    var $spi;
    var $arc;
    var $title;
    var $degChar;

    function TimingDiagram ($title, $eo, $to, $ic, $id, $spi)
    {
      $this->title = $title;
      $this->eo = $eo;
      $this->to = $to;
      $this->ic = $ic;
      $this->id = $id;
      $this->spi = $spi;

      $this->degChar = '°';
      $this->image = ImageCreateTruecolor($this->WIDTH, $this->HEIGHT);
      $this->InitColors();

      $this->arc_y = $this->HEIGHT / 12;

      $xmax = $this->WIDTH - (2 * $this->XMIN);
      $ymax = $this->HEIGHT - (2 * $this->YMIN);
      ImageFilledRectangle($this->image, $this->XMIN, $this->YMIN,
                           $xmax, $ymax, $this->BG_COLOR);
    }

    function initColors ()
    {
      $this->BG_COLOR = ImageColorAllocate($this->image, 255, 255, 255);
      $this->TITLE_COLOR = ImageColorAllocate($this->image, 0, 0, 120);
      $this->AXIS_COLOR = ImageColorAllocate($this->image, 200, 200, 200);

      $this->IN_COLOR = ImageColorAllocate($this->image, 180, 180, 180);
      $this->TR_COLOR = ImageColorAllocate($this->image, 120, 120, 120);
      $this->EX_COLOR = ImageColorAllocate($this->image, 80, 80, 80);
      $this->LAP_COLOR = ImageColorAllocate($this->image, 140, 140, 140);
    }

    function render ()
    {
      $x0 = $this->WIDTH  / 2;
      $y0 = $this->HEIGHT  / 2;
      $this->drawTitle($x0, $y0);
      $this->drawSPI($x0, $y0);
      $this->drawExhaust($x0, $y0);
      $this->drawInlet($x0, $y0);
      $this->drawSPI($x0, $y0);
      $this->drawTransfer($x0, $y0);
      $this->drawRot($x0, $y0);
      Header("Content-type: image/png");
      ImagePng($this->image);
      ImageDestroy($this->image);
    }

    function drawTitle ()
    {
      $st = "Timing Diagram for $this->title.";
      $fnt = 5;
      $dx = ($this->WIDTH - (ImageFontWidth($fnt) * strlen($st))) / 2;
      $dy = ($this->YMARGIN - ImageFontHeight($fnt)) / 2;
      imagestring($this->image, $fnt, $dx, $dy, $st, $this->TITLE_COLOR);
    }

    function drawSPI ($x0, $y0)
    {
      if (is_numeric($this->spi)) {
        $end = 270 - $this->spi;
        $start = 270 + $this->spi;
        $dx1 = .64 * $this->WIDTH;
        $dy1 = .64 * $this->HEIGHT;
        $dim = $this->arc_y * .75;
        $dx2 = $dx1 - $dim;
        $dy2 = $dy1 - $dim;
        ImageFilledArc($this->image, $x0, $y0, $dx1, $dy1, $end, $start,
                       $this->IN_COLOR, IMAGE_ARC_PIE);
        $res = ImageFilledArc($this->image, $x0, $y0, $dx2, $dy2, $end-1, $start+1,
                       $this->BG_COLOR, IMAGE_ARC_PIE);

        $x = $this->WIDTH * 0.1;
        $y = $this->HEIGHT * (($this->ic > 29) ? 0.3 : 0.2);
        $this->labelEvent($x, $y, "SPI ends", "ATDC", $this->spi);
        $this->labelEvent($this->WIDTH - $x, $y, "SPI starts", "ABDC",
                         (180 - $this->spi));
        // Drawing SPI will have trashed the Inlet duration label
        $fnt = 3;
        $id = (empty($this->id) ? (2 * $this->ic) : $this->id);
        $lab = sprintf('Inlet %.0f%s', $id, $this->degChar);
        $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
        $dy = ($y0 - (.22 * $this->HEIGHT) - ImageFontHeight($fnt));
        Imagestring($this->image, $fnt, $dx, $dy, $lab, $this->TITLE_COLOR);
        $lab = sprintf('with %.0f%s', $this->spi * 2, $this->degChar);
        $dy += ImageFontHeight($fnt);
        $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
        Imagestring($this->image, $fnt, $dx, $dy, $lab, $this->TITLE_COLOR);
        $lab = 'sub-piston induction';
        $dy += ImageFontHeight($fnt);
        $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
        Imagestring($this->image, $fnt, $dx, $dy, $lab, $this->TITLE_COLOR);
      }
    }

    function drawExhaust ($x0, $y0)
    {
      if ($this->eo > 0) {
        $ex = 180 - $this->eo;
        $eo = 90 + $ex;
        $ec = 90 - $ex;
        $dx1 = .8 * $this->WIDTH;
        $dy1 = .8 * $this->HEIGHT;
        $dx2 = $dx1 - $this->arc_y;
        $dy2 = $dy1 - $this->arc_y;
        ImageFilledArc($this->image, $x0, $y0, $dx1, $dy1, $ec, $eo,
                       $this->EX_COLOR, IMAGE_ARC_PIE);
        ImageFilledArc($this->image, $x0, $y0, $dx2, $dy2, $ec-1, $eo+1,
                       $this->BG_COLOR, IMAGE_ARC_PIE);

        $fnt = 3;
        $lab = sprintf('Exhaust %.0f%s', (2 * $ex), $this->degChar);
        $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
        $dy = ($y0 + (.46 * $this->HEIGHT) - ImageFontHeight($fnt));
        Imagestring($this->image, $fnt, $dx, $dy, $lab, $this->TITLE_COLOR);

        $x = $this->WIDTH * 0.12;
        $y = $this->HEIGHT * 0.86;
        $this->labelEvent($x, $y, "Exhaust opens", "ATDC", $this->eo);
        $this->labelEvent($this->WIDTH - $x, $y, "Exhaust closes", "ABDC",
                          180 - $this->eo);
      }
    }

    function drawTransfer ($x0, $y0)
    {
      if ($this->to > 0) {
        $tr = 180 - $this->to;
        $to = 90 + $tr;
        $tc = 90 - $tr;
        $dx1 = .7 * $this->WIDTH;
        $dy1 = .7 * $this->HEIGHT;
        $dx2 = $dx1 - $this->arc_y;
        $dy2 = $dy1 - $this->arc_y;
        ImageFilledArc($this->image, $x0, $y0, $dx1, $dy1, $tc, $to,
                       $this->TR_COLOR, IMAGE_ARC_PIE);
        ImageFilledArc($this->image, $x0, $y0, $dx2, $dy2, $tc-1, $to+1,
                       $this->BG_COLOR, IMAGE_ARC_PIE);

        // Special case where FRV inlet overlaps transfer close
        if (!empty($this->id)) {
          $io = ($this->id - $this->ic) - 90;
          if ($io > $tc) {
            ImageFilledArc($this->image, $x0, $y0, $dx1, $dy1, $tc, $io,
                           $this->LAP_COLOR, IMAGE_ARC_PIE);
            ImageFilledArc($this->image, $x0, $y0, $dx2, $dy2, $tc-1, $io+1,
                           $this->BG_COLOR, IMAGE_ARC_PIE);
          }
        }
        $fnt = 3;
        $lab = sprintf('Transfer %.0f%s', (2 * $tr), $this->degChar);
        $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
        $dy = ($y0 + (.25 * $this->HEIGHT) - ImageFontHeight($fnt));
        Imagestring($this->image, $fnt, $dx, $dy, $lab, $this->TITLE_COLOR);

        $x = $this->WIDTH * 0.35;
        $y = $this->HEIGHT * 0.65;
        $this->labelEvent($x, $y, "Transfer opens", "ATDC", $this->to);
        $this->labelEvent($this->WIDTH - $x, $y, "Transfer closes", "ABDC",
                          180 - $this->to);
      }
    }

    function drawInlet ($x0, $y0)
    {
      if (is_numeric($this->ic)) {
        $ic = 270 - $this->ic;
        $id = (is_numeric($this->id) ? $this->id : 2 * $this->ic);
        $io = $ic + $id;
        $dx1 = .7 * $this->WIDTH;
        $dy1 = .7 * $this->HEIGHT;
        $dx2 = $dx1 - $this->arc_y;
        $dy2 = $dy1 - $this->arc_y;
        ImageFilledArc($this->image, $x0, $y0, $dx1, $dy1, $ic, $io,
                       $this->IN_COLOR, IMAGE_ARC_PIE);
        ImageFilledArc($this->image, $x0, $y0, $dx2, $dy2, $ic-2, $io+2,
                       $this->BG_COLOR, IMAGE_ARC_PIE);

        $fnt = 3;
        $id = (empty($this->id) ? (2 * $this->ic) : $this->id);
        $lab = sprintf('Inlet %.0f%s', $id, $this->degChar);
        $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
        $dy = ($y0 - (.22 * $this->HEIGHT) - ImageFontHeight($fnt));
        Imagestring($this->image, $fnt, $dx, $dy, $lab, $this->TITLE_COLOR);

        $x = $this->WIDTH * 0.13;
        $y = $this->HEIGHT * 0.2;
        $isBTDC = $this->ic < 0;
        $tag = $isBTDC ? 'BTDC' : 'ATDC';
        if ($isBTDC || ($this->ic < 30)) {
          $x = $this->WIDTH -
               ($isBTDC ? ($this->WIDTH * 0.3) : ($this->WIDTH * 0.65));
          $y = $this->HEIGHT * 0.12;
        }
        $this->labelEvent($x, $y, "Inlet closes", $tag, abs($this->ic));

        $x = $this->WIDTH * 0.13;
        $y = $this->HEIGHT * 0.2;
        if ($isBTDC || ($this->ic < 30)) {
        $x = $this->WIDTH * 0.1;
          $y = $this->HEIGHT * 0.3;
        }
        $tmp = (is_numeric($this->id)) ? ($this->id - $this->ic) : $this->ic;
        $this->labelEvent($this->WIDTH-$x, $y, "Inlet opens", "ABDC", 180-$tmp);
      }
    }

    function labelEvent ($x0, $y0, $lab1, $st2, $angle)
    {
      $fnt = 2;
      $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab1)) / 2);
      $dy = $y0 - ImageFontHeight($fnt);
      Imagestring($this->image, $fnt, $dx, $dy, $lab1, $this->TITLE_COLOR);
      $lab2 = sprintf('%.1f%s %s', $angle, $this->degChar, $st2);
      $dx = ($x0 - (ImageFontWidth($fnt) * strlen($lab2)) / 2);
      Imagestring($this->image, $fnt, $dx, $y0, $lab2, $this->TITLE_COLOR);
    }

    function drawRot ($x0, $y0)
    {
      $xtick = $this->WIDTH / 30;
      ImageLine($this->image,
                $x0 - $xtick, $y0, $x0 + $xtick, $y0,
                $this->AXIS_COLOR);
      $ytick = $this->HEIGHT / 28;
      ImageLine($this->image,
                $x0, $y0 + $ytick, $x0, $y0 - (2 * $ytick),
                $this->AXIS_COLOR);
      $xrad = $this->WIDTH / 8;
      $yrad = $this->HEIGHT / 8;
      ImageArc($this->image,
               $x0, $y0, $xrad, $yrad, 270, 180, $this->AXIS_COLOR);
      $ahx = $xrad / 8;
      $ahy = $yrad / 15;
      $dy = ($yrad / 2) - ($ahy / 2);
      $points = array(($x0 - $ahx), ($y0 - $dy),
                      ($x0 + $ahx), ($y0 - $dy - $ahy),
                      ($x0 + $ahx), ($y0 - $dy + $ahy),
                      ($x0 - $ahx), ($y0 - $dy));
      ImageFilledPolygon($this->image, $points, 4, $this->AXIS_COLOR);
      $lab = "TDC";
      $fnt = 3;
      $tx = ($x0 - (ImageFontWidth($fnt) * strlen($lab)) / 2);
      $ty = ($y0 - ( .6 * $yrad) - ImageFontHeight($fnt));
      Imagestring($this->image, $fnt, $tx, $ty, $lab, $this->TITLE_COLOR);

      if (($this->eo > 0) && ($this->to> 0) ) {
        $x = $this->WIDTH * 0.092;
        $y = $this->HEIGHT * 0.93;

        $this->labelEvent($x, $y, 'Blowdown:', '', ($this->to - $this->eo));
      }
    }

}

?>

4

1 に答える 1

0

ドキュメント ( http://us2.php.net/manual/fr/function.imagefilledarc.php ) では、IMAGE_ARC_PIE ではなくIMG_ARC_PIEを使用しています。

PHP 5.3.8 に置き換えて試したところ、次の結果が得られました。 ここに画像の説明を入力

于 2012-06-12T08:25:40.487 に答える