Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- 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;}
- function gradient($width,$height,$start,$end) {
- $im = imagecreatetruecolor($width,$height);
- list($r1,$g1,$b1) = hex2rgb($start);
- list($r2,$g2,$b2) = hex2rgb($end);
- for ($i; $i < imagesy($im); $i++) {
- $old_r = $r;
- $old_g = $g;
- $old_b = $b;
- $r = ($r2-$r1 != 0) ? intval($r1+($r2-$r1) * ($i/imagesy($im))) : $r1;
- $g = ($g2-$g1 != 0) ? intval($g1+($g2-$g1) * ($i/imagesy($im))) : $g1;
- $b = ($b2-$b1 != 0) ? intval($b1+($b2-$b1) * ($i/imagesy($im))) : $b1;
- if ("$old_r,$old_g,$old_b" != "$r,$g,$b")
- $fill = imagecolorallocate($im, $r, $g, $b);
- imagefilledrectangle($im, 0, $i, imagesx($im), $i, $fill);
- }
- return $im;
- }
- /* HP/Mana Script
- By: x-treme
- Usage: ?hp/mana=currentvalue&m=maxvalue
- ex. ?hp=55&m=100
- */
- // Settings
- $width = 200; // in pixels
- $height = 30; // in pixels
- $fontsize = 12; // in points
- $font = "lunchds.ttf";
- // Main variables and setup
- error_reporting(0);
- putenv("GDFONTPATH=".realpath("."));
- $value = (empty($_GET['hp'])) ? ((empty($_GET['mana'])) ? 0 : (int)$_GET['mana']) : (int)$_GET['hp'];
- $max = (empty($_GET['m'])) ? 0 : $_GET['m'];
- $barWidth = round(($value / $max) * $width, 0);
- $barWidth = ($barWidth < 3) ? 3 : $barWidth;
- $type = (empty($_GET['hp'])) ? ((empty($_GET['mana'])) ? "" : "Mana") : "HP";
- $atk = isset($_GET['atk']) ? $_GET['atk'] : 'NA'; //Added for ATK
- $def = isset($_GET['def']) ? $_GET['def'] : 'NA'; //DEF and SPE
- $spe = isset($_GET['spe']) ? $_GET['spe'] : 'NA'; //stats.
- $name = isset($_GET['n']) ? $_GET['n'] : 'Unknown'; //stats.
- // Create image + define colors
- $image = imagecreatetruecolor($width, $height);
- $black = imagecolorallocate($image, 0, 0, 0);
- $white = imagecolorallocate($image, 255, 255, 255);
- $error = imagecolorallocate($image, 0, 255, 255); // Color for error messages
- $red = imagecolorallocate($image, 255, 0, 0);
- $blue = imagecolorallocate($image, 0, 0, 255);
- $green = imagecolorallocate($image, 0, 255, 0);
- imagefilledrectangle($image, 0, 20, 30, 200, $black);
- // Error handling
- if ($max < $value) {
- imagestring($image, 3, 6, 2, "Max HP/mana is smaller than", $error);
- imagestring($image, 3, 45, 14, "current HP/mana!", $error);
- header("Content-Type: image/png");
- imagepng($image);
- }
- if (empty($_GET['hp']) && empty($_GET['mana'])) {
- imagestring($image, 5, 22, 6, "No HP or mana set!", $error);
- header("Content-Type: image/png");
- imagepng($image);
- }
- if ($value < 0 || $max < 0) {
- imagestring($image, 3, 60, 2, "HP/Mana is a", $error);
- imagestring($image, 3, 50, 14, "negative number!", $error);
- header("Content-Type: image/png");
- imagepng($image);
- }
- // Set gradients
- $barGradient = gradient($width, $height, "F2F9FE", "D6F0FD");
- $hpManaGradient = ($type == "HP") ? gradient($barWidth, $height, "D10418", "6D0019") : (($type == "Mana") ? gradient($barWidth, $height, "00B7EA", "009EC3") : false);
- // Find bounding boxes for text
- $TTFBox = imagettfbbox(12, 0, $font, $value." / ".$max);
- $x = ceil(($width - $TTFBox[2]) / 4);
- $y = ceil(($height - $TTFBox[5]) / 2);
- // Copy layers
- imagecopyresampled($image, $barGradient, 0, 0, 0, 0, $width, $height, $width, $height);
- imagefilledrectangle($image, 0, 0, 200, 30, $black);
- imagecopyresampled($image, $hpManaGradient, 0, 0, 0, 0, $barWidth, $height, $barWidth, $height);
- imagerectangle($image, 0, 0, $width - 1, $height - 1, $black); // Double border
- imagerectangle($image, 1, 1, $width - 2, $height - 2, imagecolorallocate($image, 60, 60, 60));
- imagettftext($image, $fontsize, 0, $x-1, $y-1+5, $black, $font, $value." / ".$max); // Text border
- imagettftext($image, $fontsize, 0, $x+1, $y+1+5, $black, $font, $value." / ".$max); // Could have wrapped this in a function...
- imagettftext($image, $fontsize, 0, $x-1, $y+1+5, $black, $font, $value." / ".$max);
- imagettftext($image, $fontsize, 0, $x+1, $y-1+5, $black, $font, $value." / ".$max);
- imagettftext($image, $fontsize, 0, $x+1, $y+5, $black, $font, $value." / ".$max);
- imagettftext($image, $fontsize, 0, $x, $y+1+5, $black, $font, $value." / ".$max);
- imagettftext($image, $fontsize, 0, $x-1, $y+5, $black, $font, $value." / ".$max);
- imagettftext($image, $fontsize, 0, $x, $y-1+5, $black, $font, $value." / ".$max);
- imagettftext($image, $fontsize, 0, $x, $y+5, $white, $font, $value." / ".$max); // ... and the actual text
- ImageString($image, 2, 3, 0, $name, $black);
- ImageString($image, 2, 3, 2, $name, $black);
- ImageString($image, 2, 4, 1, $name, $black);
- ImageString($image, 2, 2, 1, $name, $black);
- ImageString($image, 2, 3, 1, $name, $white);
- ImageString($image, 1, 130, 2, " ATK: ".$atk, $black);
- ImageString($image, 1, 130, 4, " ATK: ".$atk, $black);
- ImageString($image, 1, 131, 3, " ATK: ".$atk, $black);
- ImageString($image, 1, 129, 3, " ATK: ".$atk, $black);
- ImageString($image, 1, 130, 3, " ATK: ".$atk, $green);
- ImageString($image, 1, 130, 10, " DEF: ".$def, $black);
- ImageString($image, 1, 130, 12, " DEF: ".$def, $black);
- ImageString($image, 1, 131, 11, " DEF: ".$def, $black);
- ImageString($image, 1, 129, 11, " DEF: ".$def, $black);
- ImageString($image, 1, 130, 11, " DEF: ".$def, $green);
- ImageString($image, 1, 130, 18, " SPE: ".$spe, $black);
- ImageString($image, 1, 130, 20, " SPE: ".$spe, $black);
- ImageString($image, 1, 131, 19, " SPE: ".$spe, $black);
- ImageString($image, 1, 129, 19, " SPE: ".$spe, $black);
- ImageString($image, 1, 130, 19, " SPE: ".$spe, $green);
- // Output image
- header("Content-Type: image/png");
- imagepng($image);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement