imagefrompng质量差

时间:2014-07-07 11:30:29

标签: php gd

我正在尝试从我们的某个服务器创建状态图像,但“背景图像”的质量看起来非常糟糕。下面是php文件的链接,之后是我正在使用的图像的链接。

http://www.tijmenschoemaker.nl/steamStatus/monitor.php

出于某种原因,它真的很糟糕。 这是真实的图像: http://www.tijmenschoemaker.nl/steamStatus/waspforum.png

<?php

/**
 * This code is free software; you can redistribute it and/or modify it under
 * the terms of the new BSD License.
 *
 * Copyright (c) 2010-2013, Sebastian Staudt
 *
 * @author  Sebastian Staudt
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package steam-condenser
 */

define('STEAM_CONDENSER_PATH', dirname(__FILE__) . '/');
define('STEAM_CONDENSER_VERSION', '1.3.7');

require_once STEAM_CONDENSER_PATH . 'steam/servers/GoldSrcServer.php';
require_once STEAM_CONDENSER_PATH . 'steam/servers/MasterServer.php';
require_once STEAM_CONDENSER_PATH . 'steam/servers/SourceServer.php';
require_once STEAM_CONDENSER_PATH . 'steam/community/SteamId.php';

// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'arial.ttf';


try{
    $server = new GoldSrcServer('127.0.0.1', 27016);
    $server->initialize();
    $playersMax = $server->infoHash['maxPlayers'];
    $servername = $server->infoHash['serverName'];
    $playersOnline = $server->infoHash['numberOfPlayers'];
    $serverName = $server->infoHash[ 'serverName'];
    $gameVersion = $server->infoHash['gameVersion'];
    $serverIP = "149.210.163.62";
    $serverPort = $server->infoHash['serverPort'];


$im = imagecreatefrompng('http://www.tijmenschoemaker.nl/steamStatus/waspforum.png')
    or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 0,0,0);
imagestring($im, 1, 5, 12, "Server Name ".$serverName, $text_color);
imagestring($im, 1, 5, 25, "Server Adress ".$serverIP.":".$serverPort, $text_color);
imagestring($im, 1, 5, 35, "Status: Online", $text_color);
imagestring($im, 1, 5, 45, "Players ".$playersOnline."/".$playersMax."",$text_color);
imagestring($im, 1, 5, 55, "Version: ".$gameVersion, $text_color);

header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);

    }
    catch(Exception $e)
    {
$im = @imagecreatefrompng('http://www.tijmenschoemaker.nl/steamStatus/waspforum.png')
    or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "Offline" , $text_color);
header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);

    }




?>

2 个答案:

答案 0 :(得分:0)

此功能应接受压缩&#39;参数。尝试更改行 -

imagepng($im);

要:

 imagepng($im, NULL, 0);

答案 1 :(得分:0)

您可以使用以下代码设置透明背景:

    $trans = imagecolorallocatealpha($im, 0, 0, 0, 127);
    imagesavealpha($im, true);
    imagefill($im, 0, 0, $trans);