Advertisement
Lightvayne

Untitled

May 6th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.14 KB | None | 0 0
  1. <?php
  2.     function hex2rgb($color){$color=str_replace('#','',$color);$s=strlen($color)/ 3;$rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s));$rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s));$rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s));return $rgb;}
  3.     function gradient($width,$height,$start,$end) {
  4.         $im = imagecreatetruecolor($width,$height);
  5.         list($r1,$g1,$b1) = hex2rgb($start);
  6.         list($r2,$g2,$b2) = hex2rgb($end);
  7.         for ($i; $i < imagesy($im); $i++) {
  8.             $old_r = $r;
  9.             $old_g = $g;
  10.             $old_b = $b;
  11.             $r = ($r2-$r1 != 0) ? intval($r1+($r2-$r1) * ($i/imagesy($im))) : $r1;
  12.             $g = ($g2-$g1 != 0) ? intval($g1+($g2-$g1) * ($i/imagesy($im))) : $g1;
  13.             $b = ($b2-$b1 != 0) ? intval($b1+($b2-$b1) * ($i/imagesy($im))) : $b1;
  14.             if ("$old_r,$old_g,$old_b" != "$r,$g,$b")
  15.                 $fill = imagecolorallocate($im, $r, $g, $b);
  16.             imagefilledrectangle($im, 0, $i, imagesx($im), $i, $fill);
  17.         }
  18.         return $im;
  19.     }
  20.  
  21.     /*  HP/Mana Script
  22.         By: x-treme
  23.         Usage:  ?hp/mana=currentvalue&m=maxvalue
  24.             ex. ?hp=55&m=100
  25.     */
  26.  
  27.     // Settings
  28.     $width = 200;   // in pixels
  29.     $height = 30;   // in pixels
  30.     $fontsize = 12; // in points
  31.     $font = "lunchds.ttf";
  32.    
  33.    
  34.    
  35.     // Main variables and setup
  36.     error_reporting(0);
  37.     putenv("GDFONTPATH=".realpath("."));
  38.     $value = (empty($_GET['hp'])) ? ((empty($_GET['mana'])) ? 0 : (int)$_GET['mana']) : (int)$_GET['hp'];
  39.     $max = (empty($_GET['m'])) ? 0 : $_GET['m'];
  40.     $barWidth = round(($value / $max) * $width, 0);
  41.     $barWidth = ($barWidth < 3) ? 3 : $barWidth;
  42.     $type = (empty($_GET['hp'])) ? ((empty($_GET['mana'])) ? "" : "Mana") : "HP";
  43.     $atk = isset($_GET['atk']) ? $_GET['atk'] : 'NA';   //Added for ATK
  44.     $def = isset($_GET['def']) ? $_GET['def'] : 'NA';   //DEF and SPE
  45.     $spe = isset($_GET['spe']) ? $_GET['spe'] : 'NA';   //stats.
  46.     $name = isset($_GET['n']) ? $_GET['n'] : 'Unknown'; //stats.
  47.  
  48.     // Create image + define colors
  49.     $image = imagecreatetruecolor($width, $height);
  50.     $black = imagecolorallocate($image, 0, 0, 0);
  51.     $white = imagecolorallocate($image, 255, 255, 255);
  52.     $error = imagecolorallocate($image, 0, 255, 255);   // Color for error messages
  53.     $red = imagecolorallocate($image, 255, 0, 0);
  54.     $blue = imagecolorallocate($image, 0, 0, 255);
  55.     $green = imagecolorallocate($image, 0, 255, 0);
  56.    
  57.     imagefilledrectangle($image, 0, 20, 30, 200, $black);
  58.     // Error handling
  59.     if ($max < $value) {
  60.         imagestring($image, 3, 6, 2, "Max HP/mana is smaller than", $error);
  61.         imagestring($image, 3, 45, 14, "current HP/mana!", $error);
  62.         header("Content-Type: image/png");
  63.         imagepng($image);
  64.     }
  65.  
  66.     if (empty($_GET['hp']) && empty($_GET['mana'])) {
  67.         imagestring($image, 5, 22, 6, "No HP or mana set!", $error);
  68.         header("Content-Type: image/png");
  69.         imagepng($image);
  70.     }
  71.  
  72.     if ($value < 0 || $max < 0) {
  73.         imagestring($image, 3, 60, 2, "HP/Mana is a", $error);
  74.         imagestring($image, 3, 50, 14, "negative number!", $error);
  75.         header("Content-Type: image/png");
  76.         imagepng($image);
  77.     }
  78.  
  79.     // Set gradients
  80.     $barGradient = gradient($width, $height, "F2F9FE", "D6F0FD");
  81.     $hpManaGradient = ($type == "HP") ? gradient($barWidth, $height, "D10418", "6D0019") : (($type == "Mana") ? gradient($barWidth, $height, "00B7EA", "009EC3") : false);
  82.  
  83.     // Find bounding boxes for text
  84.     $TTFBox = imagettfbbox(12, 0, $font, $value." / ".$max);
  85.  
  86.     $x = ceil(($width - $TTFBox[2]) / 4);
  87.     $y = ceil(($height - $TTFBox[5]) / 2);
  88.  
  89.     // Copy layers
  90.     imagecopyresampled($image, $barGradient, 0, 0, 0, 0, $width, $height, $width, $height);
  91.     imagefilledrectangle($image, 0, 0, 200, 30, $black);
  92.     imagecopyresampled($image, $hpManaGradient, 0, 0, 0, 0, $barWidth, $height, $barWidth, $height);
  93.     imagerectangle($image, 0, 0, $width - 1, $height - 1, $black);     // Double border
  94.     imagerectangle($image, 1, 1, $width - 2, $height - 2, imagecolorallocate($image, 60, 60, 60));
  95.     imagettftext($image, $fontsize, 0, $x-1, $y-1+5, $black, $font, $value." / ".$max);   // Text border
  96.     imagettftext($image, $fontsize, 0, $x+1, $y+1+5, $black, $font, $value." / ".$max);   // Could have wrapped this in a function...
  97.     imagettftext($image, $fontsize, 0, $x-1, $y+1+5, $black, $font, $value." / ".$max);
  98.     imagettftext($image, $fontsize, 0, $x+1, $y-1+5, $black, $font, $value." / ".$max);
  99.     imagettftext($image, $fontsize, 0, $x+1, $y+5, $black, $font, $value." / ".$max);
  100.     imagettftext($image, $fontsize, 0, $x, $y+1+5, $black, $font, $value." / ".$max);
  101.     imagettftext($image, $fontsize, 0, $x-1, $y+5, $black, $font, $value." / ".$max);
  102.     imagettftext($image, $fontsize, 0, $x, $y-1+5, $black, $font, $value." / ".$max);
  103.     imagettftext($image, $fontsize, 0, $x, $y+5, $white, $font, $value." / ".$max);       // ... and the actual text
  104.  
  105.     ImageString($image, 2, 3, 0, $name, $black);
  106.     ImageString($image, 2, 3, 2, $name, $black);
  107.     ImageString($image, 2, 4, 1, $name, $black);
  108.     ImageString($image, 2, 2, 1, $name, $black);
  109.     ImageString($image, 2, 3, 1, $name, $white);   
  110.    
  111.     ImageString($image, 1, 130, 2, " ATK: ".$atk, $black);
  112.     ImageString($image, 1, 130, 4, " ATK: ".$atk, $black);
  113.     ImageString($image, 1, 131, 3, " ATK: ".$atk, $black);
  114.     ImageString($image, 1, 129, 3, " ATK: ".$atk, $black);
  115.     ImageString($image, 1, 130, 3, " ATK: ".$atk, $green);
  116.    
  117.     ImageString($image, 1, 130, 10, " DEF: ".$def, $black);
  118.     ImageString($image, 1, 130, 12, " DEF: ".$def, $black);
  119.     ImageString($image, 1, 131, 11, " DEF: ".$def, $black);
  120.     ImageString($image, 1, 129, 11, " DEF: ".$def, $black);
  121.     ImageString($image, 1, 130, 11, " DEF: ".$def, $green);
  122.    
  123.     ImageString($image, 1, 130, 18, " SPE: ".$spe, $black);
  124.     ImageString($image, 1, 130, 20, " SPE: ".$spe, $black);
  125.     ImageString($image, 1, 131, 19, " SPE: ".$spe, $black);
  126.     ImageString($image, 1, 129, 19, " SPE: ".$spe, $black);
  127.     ImageString($image, 1, 130, 19, " SPE: ".$spe, $green);
  128.  
  129.     // Output image
  130.     header("Content-Type: image/png");
  131.     imagepng($image);
  132. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement