Advertisement
RyDeR_

Server Signature

Feb 29th, 2012
1,979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. <?php
  2.  
  3.     /*
  4.         PHP SA:MP Server Signature Creator
  5.         Copyright © 2011 RyDeR`
  6.     */
  7.    
  8.     header("Content-Type: image/png");
  9.    
  10.     $szData = $_GET['serverIP'];
  11.     $bHasException = false;
  12.    
  13.     if(isset($szData))
  14.     {
  15.         require("Source/Includes/sampQuery.php");
  16.        
  17.         list($szIP, $szPort) = explode(':', $szData);
  18.        
  19.         try
  20.         {
  21.             $cQuery = new sampQuery($szIP, $szPort);
  22.         }
  23.         catch(sampQueryException $cException)
  24.         {
  25.             $bHasException = true;
  26.         }
  27.        
  28.         try
  29.         {
  30.             $cQuery->getServerInfo($iPassword, $iPlayers, $iSlot, $szHostname, $szGameMode, $szMap);
  31.         }
  32.         catch(sampQueryException $cException)
  33.         {
  34.             $bHasException = true;
  35.            
  36.         }
  37.        
  38.         $rImage = imagecreate(675, 18);
  39.        
  40.         if($rImage)
  41.         {
  42.             $rImageIcon = imagecreatefrompng("Source/Images/" . (($iPassword) ? ("Locked") : ("Unlocked")) . ".png");
  43.            
  44.             if($rImageIcon)
  45.             {
  46.                 $iWhite = imagecolorallocate($rImage, 0xFF, 0xFF, 0xFF);
  47.                 $iBlack = imagecolorallocate($rImage, 0x0, 0x0, 0x0);
  48.                 $iGrey = imagecolorallocate($rImage, 0xEF, 0xEF, 0xEF);
  49.  
  50.                 imagecopymerge($rImage, $rImageIcon, 7, 2, 0, 0, 13, 14, 100);
  51.                 imagefill($rImage, 0, 0, $iGrey);
  52.                                    
  53.                 $fX = 28.0;
  54.                
  55.                 imagefilledrectangle($rImage, $fX, 0, $fX += 0.5, 18, $iWhite);
  56.                 imagefilledrectangle($rImage, $fX += 250.0, 0, $fX, 18, $iWhite);
  57.                 imagefilledrectangle($rImage, $fX += 60.0, 0, $fX, 18, $iWhite);
  58.                 imagefilledrectangle($rImage, $fX += 120.0, 0, $fX, 18, $iWhite);
  59.                 imagefilledrectangle($rImage, $fX += 90.0, 0, $fX, 18, $iWhite);
  60.                                    
  61.                 $szFont = "Source/Fonts/verdana.ttf";                              
  62.                 $fX = 32.0;
  63.                
  64.                 writeBoundedImageText($rImage, $fX, 13.0, 197, 7.5, $szFont, $iBlack, $szHostname);
  65.                 writeBoundedImageText($rImage, $fX += 250, 13.0, 45, 7.5, $szFont, $iBlack, $iPlayers . '/' . $iSlot);
  66.                 writeBoundedImageText($rImage, $fX += 60.0, 13.0, 97, 7.5, $szFont, $iBlack, $szGameMode);
  67.                 writeBoundedImageText($rImage, $fX += 120.0, 13.0, 70, 7.5, $szFont, $iBlack, $szMap);
  68.                 writeBoundedImageText($rImage, $fX += 90.0, 13.0, 146, 7.5, $szFont, $iBlack, $szIP . ':' . $szPort);
  69.                
  70.                 imagepng($rImage);
  71.                
  72.                 imagecolordeallocate($rImage, $iWhite);                
  73.                 imagecolordeallocate($rImage, $iBlack);
  74.                 imagecolordeallocate($rImage, $iGrey);
  75.                
  76.                 imagedestroy($rImage);
  77.                 imagedestroy($rImageIcon);
  78.             }
  79.         }
  80.     }
  81.    
  82.     function writeBoundedImageText(&$rImage, $fX, $fY, $iWidth, $fSize, $szFont, $iColor, $szText) // RyDeR`
  83.     {
  84.         $iTmpWidth = 0;
  85.         $iTextLen = strlen($szText);
  86.        
  87.         for($i = 0; $i < $iTextLen; ++$i)
  88.         {
  89.             $aDim = imagettfbbox($fSize, 0.0, $szFont, $szText[$i]);
  90.            
  91.             $iTmpWidth += ($aDim[2] - $aDim[0]);
  92.            
  93.             if($iTmpWidth > $iWidth)
  94.             {
  95.                 imagettftext($rImage, $fSize, 0.0, $fX, $fY, $iColor, $szFont, substr($szText, 0, $i));
  96.                 return ;
  97.             }
  98.         }
  99.         imagettftext($rImage, $fSize, 0.0, $fX, $fY, $iColor, $szFont, $szText);
  100.     }
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement