2013-11-20 77 views
-1

我发现这个软件包,我试图运行该示例并显示括号。锦标赛生成器PHP

但它输出一些奇怪的字符:

�PNG IHDR�Ht�4PLTE���U��~�IDATx����o�V��GIW&q�*�=ު`B�&��?�?!R*Mv� 

你明白了吧。

我在想,这是因为:

// If GD-lib is installed, the below code will draw the bracket of the knock-out  tournament. 
if ($GDLIB_INSTALLED) { 
$im = $KO->getImage("Tournament name here"); 
header('Content-type: image/png'); 
imagepng($im); 
imagedestroy($im); 
} 

但我不知道如何解决它....

感谢, 阿糖胞苷

编辑:

所以我在gat说了什么之后,稍微改变了一下代码。

在我的控制,我得到: 公共职能getTest(){

// Depending on whether or not GD-lib is installed this example file will output differently. 
    $GDLIB_INSTALLED = (function_exists("gd_info")) ? true : false; 


    // Lets create a knock-out tournament between some of our dear physicists. 
    $competitors = array(
     'Paul A.M. Dirac', 
     'Hans Christian Oersted', 
     'Murray Gell-Mann', 
     'Marie Curie', 
     'Neils Bohr', 
     'Richard P. Feynman', 
     'Max Planck'); 

    // Create initial tournament bracket. 
    $KO = new TournamentGeneratorGD($competitors); 
    $KO->setResByMatch(1, 1, 4, 0); 


    if($GDLIB_INSTALLED){ 
     $im = $KO->getImage("Tournament name here"); 
     return View::make('test_img') 
        ->with('im', $im); 
    } 
    else 
     return View::make('home'); 
} 

而且在我test_img.php页,我得到这个:

<?php 
header('Content-type: image/png'); 
imagepng($im); 
imagedestroy($im); 
?> 

它不反正工作..

+0

您是否安装了GD库? – j08691

+0

是所有的代码?因为它看起来像头没有被应用,头文件已经发送错误? ; p –

+0

@劳伦斯,不,它不是所有的代码。但我改变了什么加特说,它并没有解决它tho ... –

回答

1

header('Content-type: image/png');应该是输出任何东西之前,你说的第一句话。

尝试下面的代码移动到不同的源文件(img.php或东西)。

header('Content-type: image/png'); 
$im = $KO->getImage("Tournament name here"); 
imagepng($im); 
imagedestroy($im); 

然后,您可以将页面重定向到您的if ($GDLIB_INSTALLED)块中的img.php。

+0

嘿,感谢您的答复。不幸的是,它没有工作...我只是把这个:<?php header('Content-type:image/png'); imagepng($ im); imagedestroy($ im); ?> –