用pchart输出的胡言乱语

时间:2012-02-24 17:03:58

标签: php drupal drupal-7 pchart

我一直在尝试在我的drupal 7站点中使用pchart库创建图形。我已正确安装和配置pchart,当我尝试使用pcahrt提供的示例进行测试时,我会得到一个非常乱码的输出,如下所示..

  

PNGIHDR R   IDATxw \} o ^ WH \ CP + '!���M�&N����ɛ8yc'��$؉���   !PE]fǕF2jˬt})克ܹSF!X0 JZM @QRGTӲm_Е$$$$$$ K4t   iVBWf%T   IVՕħ$ R X7 pK'V7 @,_〜,>!?] LT; ^ { - [Y晧〜t35Qn:o Y)安培; |Aҫ-NN | gte2mnN#GWގ#!!!!] azzz /59eī 6ؾ} 1 TF7߸FX< wym455} [ߚ\ U%7-n的XPG(xv9〜_〜; C1P> C0sA輡“!!!!中号iiz͚5pb@ {{;我޿(瓦特ܹ{ö} S,VVzOOΝ; d,SN4 [U]瓦特?ݹs'0vҗTYÔ=:˹)TTTݻWW} EMܸqʪhsKKDfv TU09q6NYp(   ǟ|| | XUݜ2ʪ<< qou4mwtt466nyr {tkk˶m6nbc޳去%l8lqلZ]]דUR3ç s6gmryp 8 s ) 9q gڵy y j b bŊ 'oz s i =“”7ܰcǎ d m p(JJK = “”   ü术去E +,{=“{|?的,|?氖44吨} M”   U〜R%7 = “”   V] 9RG = “” > XY1ضüַz'fYv9ˎO#y的? Ӏ4+} F%吨   iVBW f%t iVBW f%tҀ 4+ $$$$$$ Y   小号 ^ BC#Fq4 ^;   F1bĈkqh#$ F1b5 .R&安培;!BC#$ FqCy JEC#F1J岚FA1bĈ2cH4 #F1 {ּ电视%1BC#楼\ HMBC#Fx6h#F1b5 \ f2pvXu2?ή #N ?? - [R [; 3;ڟEK   BC#3H؃SA P6ތJ83   = rOeb#PhrO9J {1BC /1ӛ; 5ktk6 ?| * + 15'qemM:ǤTUqO#F%P4 L< wym 455} [ߚ\Ú

这是非常冗长的,只是输出的一部分。

当我把

<img src="sites/all/libraries/pChart2.1.3/examples/example.basic.php" />

在我的页面上排队,我没有得到任何东西,只是一个带标题的空白页面。

当我在我的网页上包含example.basic.php文件时,我得到了那些胡言乱语。

下面是我的example.basic.php代码,

  <?php
     /* CAT:Misc */

    //I have installed libraries module. and the contents of pChart are present in /sites/all/libraries/pChart2.1.3

    $name = "pChart2.1.3";
    if ($path = libraries_get_path($name)) {
     include($path.'/class/pData.class.php');
    include($path.'/class/pDraw.class.php');
    include($path.'/class/pImage.class.php');
    }

     /* Include all the classes 
     include("../class/pDraw.class.php"); 
     include("../class/pImage.class.php"); 
     include("../class/pData.class.php"); */

     /* Create your dataset object */ 
     $myData = new pData(); 

     /* Add data in your dataset */ 
     $myData->addPoints(array(1,3,4,3,5));

     /* Create a pChart object and associate your dataset */ 
     $myPicture = new pImage(700,230,$myData);

     /* Choose a nice font */
     $myPicture->setFontProperties(array("FontName"=>$path.'/fonts/Forgotte.ttf',"FontSize"=>11));

     /* Define the boundaries of the graph area */
     $myPicture->setGraphArea(60,40,670,190);

     /* Draw the scale, keep everything automatic */ 
     $myPicture->drawScale();

     /* Draw the scale, keep everything automatic */ 
     $myPicture->drawSplineChart();

     /* Render the picture (choose the best way) */
     $myPicture->autoOutput("pictures/example.basic.png");

?>

FYI, 我已尝试渲染图片,如

$myPicture->autoOutput();

$myPicture->Stroke();

$myPicture->render();

但是,所有这些都给出了相同的结果..! 那我怎样才能让它发挥作用.. ??

/////////////// ADDED image.png code //////////////////////// ////////////////////////////////////////////////// ///////////

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 1.0" dir="ltr"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:dc="http://purl.org/dc/terms/"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:og="http://ogp.me/ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:sioc="http://rdfs.org/sioc/ns#"
  xmlns:sioct="http://rdfs.org/sioc/types#"
  xmlns:skos="http://www.w3.org/2004/02/skos/core#"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema#">

<head profile="http://www.w3.org/1999/xhtml/vocab">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta about="/d7/?q=node/2" property="sioc:num_replies" content="0" datatype="xsd:integer" />
<link rel="shortcut icon" href="http://localhost/d7/misc/favicon.ico" type="image/vnd.microsoft.icon" />
<meta content="test" about="/d7/?q=node/2" property="dc:title" />
<link rel="shortlink" href="/d7/?q=node/2" />
<meta name="Generator" content="Drupal 7 (http://drupal.org)" />
<link rel="canonical" href="/d7/?q=node/2" />
  <title>test | project</title>
  <style type="text/css" media="all">@import url("http://localhost/d7/modules/system/system.base.css?lzusma");
@import url("http://localhost/d7/modules/system/system.menus.css?lzusma");
@import url("http://localhost/d7/modules/system/system.messages.css?lzusma");
@import url("http://localhost/d7/modules/system/system.theme.css?lzusma");</style>
<style type="text/css" media="all">@import url("http://localhost/d7/modules/comment/comment.css?lzusma");
@import url("http://localhost/d7/sites/all/modules/date/date_api/date.css?lzusma");
@import url("http://localhost/d7/sites/all/modules/date/date_popup/themes/datepicker.1.7.css?lzusma");
@import url("http://localhost/d7/modules/field/theme/field.css?lzusma");
@import url("http://localhost/d7/modules/node/node.css?lzusma");
@import url("http://localhost/d7/modules/search/search.css?lzusma");
@import url("http://localhost/d7/modules/user/user.css?lzusma");</style>
<style type="text/css" media="all">@import url("http://localhost/d7/themes/bartik/css/layout.css?lzusma");
@import url("http://localhost/d7/themes/bartik/css/style.css?lzusma");
@import url("http://localhost/d7/themes/bartik/css/colors.css?lzusma");</style>
<style type="text/css" media="print">@import url("http://localhost/d7/themes/bartik/css/print.css?lzusma");</style>

<!--[if lte IE 7]>
<link type="text/css" rel="stylesheet" href="http://localhost/d7/themes/bartik/css/ie.css?lzusma" media="all" />
<![endif]-->

<!--[if IE 6]>
<link type="text/css" rel="stylesheet" href="http://localhost/d7/themes/bartik/css/ie6.css?lzusma" media="all" />
<![endif]-->
  <script type="text/javascript" src="http://localhost/d7/misc/jquery.js?v=1.4.4"></script>
<script type="text/javascript" src="http://localhost/d7/misc/jquery.once.js?v=1.2"></script>
<script type="text/javascript" src="http://localhost/d7/misc/drupal.js?lzusma"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {"basePath":"\/d7\/","pathPrefix":"","ajaxPageState":{"theme":"bartik","theme_token":"QE-jd8WcXtpZ1dRuiSRy-AooAlkyyPIGI7vF2twO1Js","js":{"misc\/jquery.js":1,"misc\/jquery.once.js":1,"misc\/drupal.js":1},"css":{"modules\/system\/system.base.css":1,"modules\/system\/system.menus.css":1,"modules\/system\/system.messages.css":1,"modules\/system\/system.theme.css":1,"modules\/comment\/comment.css":1,"sites\/all\/modules\/date\/date_api\/date.css":1,"sites\/all\/modules\/date\/date_popup\/themes\/datepicker.1.7.css":1,"modules\/field\/theme\/field.css":1,"modules\/node\/node.css":1,"modules\/search\/search.css":1,"modules\/user\/user.css":1,"themes\/bartik\/css\/layout.css":1,"themes\/bartik\/css\/style.css":1,"themes\/bartik\/css\/colors.css":1,"themes\/bartik\/css\/print.css":1,"themes\/bartik\/css\/ie.css":1,"themes\/bartik\/css\/ie6.css":1}}});
//--><!]]>
</script>
</head>
<body class="html not-front not-logged-in one-sidebar sidebar-first page-node page-node- page-node-2 node-type-article" >
  <div id="skip-link">
    <a href="#main-content" class="element-invisible element-focusable">Skip to main content</a>
  </div>
    <div id="page-wrapper"><div id="page">

  <div id="header" class="without-secondary-menu"><div class="section clearfix">

          <a href="/d7/" title="Home" rel="home" id="logo">
        <img src="http://localhost/d7/themes/bartik/logo.png" alt="Home" />
      </a>

          <div id="name-and-slogan">

                              <div id="site-name">
              <strong>
                <a href="/d7/" title="Home" rel="home"><span>project</span></a>
              </strong>
            </div>


      </div> <!-- /#name-and-slogan -->


          <div id="main-menu" class="navigation">
        <h2 class="element-invisible">Main menu</h2><ul id="main-menu-links" class="links clearfix"><li class="menu-218 first last"><a href="/d7/">Home</a></li>
</ul>      </div> <!-- /#main-menu -->


  </div></div> <!-- /.section, /#header -->



  <div id="main-wrapper" class="clearfix"><div id="main" class="clearfix">

          <div id="breadcrumb"><h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="/d7/">Home</a></div></div>

          <div id="sidebar-first" class="column sidebar"><div class="section">
          <div class="region region-sidebar-first">
    <div id="block-user-login" class="block block-user">

    <h2>User login</h2>

  <div class="content">
    <form action="/d7/?q=node/2&amp;destination=node/2" method="post" id="user-login-form" accept-charset="UTF-8"><div><div class="form-item form-type-textfield form-item-name">
  <label for="edit-name">Username <span class="form-required" title="This field is required.">*</span></label>
 <input type="text" id="edit-name" name="name" value="" size="15" maxlength="60" class="form-text required" />
</div>
<div class="form-item form-type-password form-item-pass">
  <label for="edit-pass">Password <span class="form-required" title="This field is required.">*</span></label>
 <input type="password" id="edit-pass" name="pass" size="15" maxlength="60" class="form-text required" />
</div>
<div class="item-list"><ul><li class="first"><a href="/d7/?q=user/register" title="Create a new user account.">Create new account</a></li>
<li class="last"><a href="/d7/?q=user/password" title="Request new password via e-mail.">Request new password</a></li>
</ul></div><input type="hidden" name="form_build_id" value="form-1CLdTDBqbmne6F7FjhizZLAe-9XZmCIa__KHgtmPeP8" />
<input type="hidden" name="form_id" value="user_login_block" />
<div class="form-actions form-wrapper" id="edit-actions"><input type="submit" id="edit-submit" name="op" value="Log in" class="form-submit" /></div></div></form>  </div>
</div>
  </div>
      </div></div> <!-- /.section, /#sidebar-first -->

    <div id="content" class="column"><div class="section">
            <a id="main-content"></a>
                    <h1 class="title" id="page-title">
          test        </h1>
                          <div class="tabs">
                  </div>
                          <div class="region region-content">
    <div id="block-system-main" class="block block-system">


  <div class="content">
    <div id="node-2" class="node node-article node-promoted node-full clearfix" about="/d7/?q=node/2" typeof="sioc:Item foaf:Document">


      <div class="meta submitted">
            <span property="dc:date dc:created" content="2012-02-24T00:32:36+05:30" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <span class="username" xml:lang="" about="/d7/?q=user/1" typeof="sioc:UserAccount" property="foaf:name">akshaynhegde</span> on Fri, 02/24/2012 - 00:32</span>    </div>

  <div class="content clearfix">
    <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded">HELLoo

下一部分是一个乱码代码..因此我无法粘贴它所以这里是那个乱码的图片.. enter image description here

在胡言乱语之后还有一些代码......如下所示,

<img src="/sites/all/libraries/pChart2.1.3/examples/example.basic.php" /></div></div></div>  </div>

      <div class="link-wrapper">
      <ul class="links inline"><li class="comment_forbidden first last"><span><a href="/d7/?q=user/login&amp;destination=node/2%23comment-form">Log in</a> or <a href="/d7/?q=user/register&amp;destination=node/2%23comment-form">register</a> to post comments</span></li>
</ul>    </div>


</div>
  </div>
</div>
  </div>

    </div></div> <!-- /.section, /#content -->


  </div></div> <!-- /#main, /#main-wrapper -->


  <div id="footer-wrapper"><div class="section">


          <div id="footer" class="clearfix">
          <div class="region region-footer">
    <div id="block-system-powered-by" class="block block-system">


  <div class="content">
    <span>Powered by <a href="http://drupal.org">Drupal</a></span>  </div>
</div>
  </div>
      </div> <!-- /#footer -->

  </div></div> <!-- /.section, /#footer-wrapper -->

</div></div> <!-- /#page, /#page-wrapper -->
  </body>
</html>

3 个答案:

答案 0 :(得分:0)

不确定你的问题是什么,似乎它输出了一个png图像,逐字节, 如果添加

会发生什么
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=image.png');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

答案 1 :(得分:0)

不知何故,标题信息未正确设置,无法直接将图像渲染到浏览器。

长话故事。使用$Image->Render("test.png")代替$Image->Stroke()并在您的页面中进行引用,如下所示:

<img src="test.png" />

答案 2 :(得分:0)

您可以参考pImage.class.php Line.171中函数autoOutput()的实现。

根据Web服务器和PHP之间的接口类型,函数执行的操作会有所不同。

因此,乱码输出是png文件的内容。如果您在页面中评论所有其他html输出,您将在浏览器中看到图表的完整图像。