为什么php创建的图像没有显示?

时间:2012-06-16 14:48:19

标签: php

我有一个问题,我有一个软件获得pc技术规格并在线发布它们我们为每个规格提供一个签名图像,这是由PHP创建的,但不再工作了; 演示链接:http://checkmyspecs.co.uk/button.php?id=646725或转到任何规格页面,例如:http://www.checkmyspecs.co.uk/display2.php?id=646725,页面下方是抓取按钮代码。

图片必须由button.php创建,这是代码:

<?php

include "db.php"; 

function getdata($viewerid) { 
$query = "SELECT * FROM data where viewerid = '$viewerid'"; 

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$data = array(); 
array_push($data,$row['bootmethod'],$row['ComputerCaption'],$row['Infrared'],$row['DayLight'],$row['ManufacturerBox'],$row['Model'],$row['cores'],$row['memory'],$row['monitor'],$row['resolution'],$row['pixels'],$row['cpuvoltage'],$row['clockspeed'],$row['AddressWidth'],$row['SocketDesignation'],$row['cpuname'],$row['loadpercent'],$row['applications'],$row['videocardname'],$row['refreshrate'],$row['videodriver'],$row['installed'],$row['hddata'],$row['directx']); 
return $data; 
} 


function LoadPNG($imgname,$cur)
{

$getvalues = getdata($cur);

/* Attempt to open */
$im = @imagecreatefrompng($imgname);
// Removes white background (made from the original transparency)
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background transparent

//Generate the text to write onto the image (the php Version).
//Don't know much about this


// Add some shadow to the text

$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$blue = imagecolorallocate($im, 0, 173, 238);
$darkblue = imagecolorallocate($im, 54, 154, 191);



$font = '/fonts/arialbd.ttf';

$ramo = $getvalues[7];
$cpuo = $getvalues[15];
$gpuo = $getvalues[18];
$screeno = $getvalues[9];

$ram = "$ramo MB"; 
$cpu = "$cpuo"; 
$gpu = "$gpuo "; 
$screen = "$screeno"; 

imagettftext($im, 11, 0, 40, 23, $black, $font, $cpu);
imagettftext($im, 11, 0, 40, 53, $black, $font, $gpu);
imagettftext($im, 11, 0, 40, 83, $black, $font, $screen);
imagettftext($im, 11, 0, 40, 113, $black, $font, $ram);


// write text
$textcolor = imagecolorallocate($im, 0, 3, 0);
return $im;
}
header('Content-Type: image/png');
$button = '/images/button.png'; 
$img = LoadPNG($button,$_GET['id']);
imagepng($img); 


?> 

1 个答案:

答案 0 :(得分:2)

您的图片不是图片。这是真正的输出:

  


  警告:imagecolorallocate():提供的参数不是 /home/checkmys/public_html/button.php 中有效的图像资源 24 <登记/>   
  警告:imagecolorallocate():提供的参数不是 /home/checkmys/public_html/button.php 中有效的图像资源 33 <登记/>   
  警告:imagecolorallocate():提供的参数不是 /home/checkmys/public_html/button.php 中有效的图像资源 34 <登记/>   
  警告:imagecolorallocate():提供的参数不是 /home/checkmys/public_html/button.php 中有效的图像资源 35 <登记/>   
  警告:imagecolorallocate():提供的参数不是 /home/checkmys/public_html/button.php 中有效的图像资源 36 <登记/>   
  警告:imagecolorallocate():提供的参数不是 /home/checkmys/public_html/button.php 中有效的图像资源 37 <登记/>   
  致命错误:在 53 /home/checkmys/public_html/button.php 中调用未定义的函数imagettftext() / p>

即使您的内容类型设置为图片,也可以使用Fiddler等工具查看此内容。如果您要移除@符号,我们可能会看到错误,说明无法创建图片的原因。

此外,您目前对SQL注入非常开放。您应该使用prepared queries with PDO来避免此问题。