dqm7854 2014-04-24 01:09
浏览 156
已采纳

PHP - imagepng无法正常工作

Well guys, first, here is my code:

<?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);

?>

We changed the servers, and now, I get this:

enter image description here

What is happening?

EDIT

Setting PHP errors to ON, I get this warning:

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

And in line 68 we have:

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

EDIT 2

Taking a deeper look into assinatura.php, I've found out a BOM before the PHP tag, but now how to remove it?

enter image description here

  • 写回答

3条回答 默认 最新

  • dp518158 2014-05-01 19:30
    关注

    Found it!!!

    Well! there was a BOM before the PHP tag. How to remove it, is very very simple. I'm using Adobe Dreamweaver, so here are the steps:

    1 - Press CTRL + J (Page Properties);

    2 - Go to the title/encoding tab, and uncheck the "Include Unicode Signature" checkbox;

    enter image description here

    Save the document, and the magic happens. Have no idea why I didn't get this error in the other server!


    And if you don't use Adobe Dreamweaver, the Notepad++ can convert to UTF-8 without BOM (Byte Order Mask):

    Notepad++: Convert to UTF-8 without BOM

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵