PHP - imagepng无法正常工作

时间:2014-04-24 01:09:08

标签: php image

好吧,首先,这是我的代码:

<?php

ob_start();

$pilot_id = $_GET['id'];

//-- Server Variables
$dbServer        = 'localhost';
$dbUser          = 'root';
$dbPassword      = '*************';
$dbName          = 'bla_tracker';

//-- Server Connection >>> DO NOT CHANGE <<<
$sql = mysql_connect("$dbServer", "$dbUser", "$dbPassword") or die(mysql_error());
$select_db = mysql_select_db("$dbName", $sql);

$query = mysql_query("SELECT * FROM acars_users WHERE `id`='".$pilot_id."' ") or die (mysql_error());
$row = mysql_fetch_array($query);
$nome = $row['nome'];
$patente = $row['rank'];
$admin = $row['admin'];
$checador = $row['checador'];

$query_horas = mysql_query("SELECT SUM(flighttime) AS `total` FROM acars_pirep WHERE iduser='".$pilot_id."'") or die (mysql_error());
$row2 = mysql_fetch_assoc($query_horas);
$total_min = $row2['total'] + ($row['horas'] * 60);
$total = round($total_min/60);

  if($admin == 1) {
     $data = "Comandante Master - $nome";
  } else {
  if($checador == 1) {
     $data = "Comandante Checador - $nome";  
  } else {
  if($patente == '4') {
     $data = "Comandante Sênior - $nome";   
  } else {
  if($patente == '3') {
     $data = "Comandante Instrutor - $nome"; 
  } else {
  if($patente == '2') {
     $data = "Comandante - $nome"; 
  } else {
  if($patente == '1') {
     $data = "Primeiro Oficial - $nome"; 
  } else {
  if($patente == '0') {
     $data = "Copiloto - $nome";     
  }}}}}}}


$rand = rand(1, 8);

$my_img = imagecreatefrompng("images/background_$rand.png");
$background = imagecolorallocate($my_img, 0, 0, 255);
$text_colour = imagecolorallocate($my_img, 255, 255, 255);


imagettftext($my_img, 11, 0, 4, 12, $text_colour, "calibril.ttf", "$data");
imagettftext($my_img, 11, 0, 340, 12, $text_colour, "calibril.ttf", "$total hrs");
imagettftext($my_img, 11, 0, 4, 98, $text_colour, "calibril.ttf", "Brasil Linhas Aéreas");
imagettftext($my_img, 11, 0, 323, 98, $text_colour, "calibril.ttf", "voebla.com");

imagesetthickness ($my_img, 5 );


header("Content-type: image/png");
imagepng($my_img);
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy($my_img);

?>

我们更改了服务器,现在,我明白了:

enter image description here

发生了什么事?

修改

将PHP错误设置为ON,我收到此警告:

Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\voebla.com\httpdocs\BLAtracker\sessoes\pilotos\modules\dados\assinatura\assinatura.php:1) in C:\Inetpub\vhosts\voebla.com\httpdocs\BLAtracker\sessoes\pilotos\modules\dados\assinatura\assinatura.php on line 68

在第68行,我们有:

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

编辑2

深入研究一下assinatura.php,我在PHP标签之前发现了一个BOM,但现在该如何删除它?

enter image description here

3 个答案:

答案 0 :(得分:7)

找到它!!!

嘛!在PHP标记之前有一个BOM。如何删除它,非常简单。我使用的是Adobe Dreamweaver,所以步骤如下:

1 - 按CTRL + J(页面属性);

2 - 转到标题/编码标签,取消选中&#34;包括Unicode签名&#34;复选框;

enter image description here

保存文档,神奇的事情发生了。不知道为什么我没有在其他服务器上收到此错误!


如果您不使用Adobe Dreamweaver,Notepad ++可以转换为没有BOM(字节顺序掩码)的UTF-8:

Notepad++: Convert to UTF-8 without BOM

答案 1 :(得分:1)

输出正确但未被识别为PNG。问题是标题未正确设置,这就是它未被识别的原因。可能是因为标题已经设置好了。

删除ob_start()并查看是否可以解决此问题。

否则检查是否存在会在其上添加另一个标头的内容,例如由.htaccess添加的标头PHP文件。

编辑:PHP错误证实了这种情况。有些东西已经设置了文件头。很可能是.htaccess为此目录中的每个PHP文件添加一个标头。这是你的问题,因为我在这个脚本上没有看到任何其他标题或回声。

答案 2 :(得分:1)

添加ob_start("ob_gzhandler");。它可能会解决您的问题。你的照片在哪里?在子目录或数据库中?

相关问题