Advertisement
Guest User

Guild Emblems

a guest
Jun 3rd, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.49 KB | None | 0 0
  1. <?php
  2. // Abyss
  3. $abyss = array(-18, 1, 275, 0.0234375, 1.09375);
  4.  
  5. // White
  6. $white = array(45, 1.44531, 10, 0.0234375, 1.5625);
  7.  
  8. // Grape
  9. $grape = array(-3,1,305,0.507813,0.937500);
  10.  
  11. // Hot Pink
  12. $hotpink = array(14, 1.21094, 340, 0.820313, 1.44531);
  13.  
  14. // Grapevine
  15. $grapevine = array(2, 1, 270, 0.507813, 1.09375);
  16.  
  17. header('Content-type: image/png');
  18. $imagebkpath = './backgrounds/1.png';
  19. $image1path = './emblems/2a.png';
  20. $image2path = './emblems/2b.png';
  21. $image_bk = imagecreatefrompng($imagebkpath);
  22. $image_1 = imagecreatefrompng($image1path);
  23. $image_2 = imagecreatefrompng($image2path);
  24. $background = imagecolorallocate($image_bk,  0,0,0);
  25. imagecolortransparent($image_bk, $background);
  26. imagealphablending($image_bk, true);
  27. imagesavealpha($image_bk, true);
  28. imagehue($image_bk, $abyss[0],$abyss[1],$abyss[2],$abyss[3],$abyss[4]);
  29. imagehue($image_1, $white[0],$white[1],$white[2],$white[3],$white[4]);
  30. imagehue($image_2, $grape[0],$grape[1],$grape[2],$grape[3],$grape[4]);
  31. imagecopy($image_1, $image_2, 0, 0, 0, 0, 256, 256);
  32. imagecopy($image_bk, $image_1, 0, 0, 0, 0, 256, 256);
  33. imagepng($image_bk);
  34. imagedestroy($image_bk);
  35. imagedestroy($image_1);
  36. imagedestroy($image_2);
  37.  
  38. function imagehue(&$image, $b,$c,$h,$s,$l) {
  39.     $width = imagesx($image);
  40.     $height = imagesy($image);
  41.     for($x = 0; $x < $width; $x++) {
  42.         for($y = 0; $y < $height; $y++) {
  43.             $rgb = imagecolorat($image, $x, $y);
  44.             $r = ($rgb >> 16) & 0xFF;
  45.             $g = ($rgb >> 8) & 0xFF;
  46.             $b = $rgb & 0xFF;            
  47.             $alpha = ($rgb & 0x7F000000) >> 24;
  48.             $rgb = array(128,26,26);
  49.             $rgb = shiftColour($rgb,$b,$c,$h,$s,$l);
  50.             imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $rgb[0], $rgb[1], $rgb[2], $alpha));
  51.         }
  52.     }
  53. }
  54.  
  55. // shiftColour from https://gist.github.com/codemasher/fb407de5587fdbd3e7c5
  56. function shiftColour($rgb,$b,$c,$h,$s,$l){
  57.     $rgb = rgb_BC($rgb,$b,$c);
  58.     $hsl = rgb2hsl($rgb);
  59.     $hsl[0] = ($hsl[0]*360+$h)/360;
  60.     $hsl[1] = $hsl[1] * $s;
  61.     $hsl[2] = $hsl[2] * $l;
  62.     $rgb = hsl2rgb($hsl);
  63.     return $rgb;
  64. }
  65.  
  66. // rgb_BC from code here: https://gist.github.com/codemasher/fb407de5587fdbd3e7c5
  67. function rgb_BC($rgb,$b,$c){
  68.     foreach($rgb as $k => $v){
  69.         $rgb[$k] = (($v+$b)-128) * $c+128;
  70.     }
  71.     return $rgb;
  72. }
  73.  
  74. //rgb2hsl from code here: https://gist.github.com/codemasher/741f30e68c6e9c7921c7
  75. function rgb2hsl($rgb){
  76.     $r = $rgb[0]/255;
  77.     $g = $rgb[1]/255;
  78.     $b = $rgb[2]/255;
  79.  
  80.     $min = min($r, $g, $b);
  81.     $max = max($r, $g, $b);
  82.     $d = $max-$min;
  83.  
  84.     $h = $s = 0;
  85.     $l = ($max+$min)/2;
  86.  
  87.     if($d > 0){
  88.         $s = $l > 0.5 ? $d/(2-$max-$min) : $d/($max+$min);
  89.         switch($max){
  90.             case $r: $h = ($g-$b)/$d+($g < $b ? 6 : 0); break;
  91.             case $g: $h = ($b-$r)/$d+2; break;
  92.             case $b: $h = ($r-$g)/$d+4; break;
  93.         }
  94.         $h /= 6;
  95.     }
  96.  
  97.     return array($h, $s, $l);
  98. }
  99.  
  100. // hsl2rgb from code here: https://gist.github.com/codemasher/741f30e68c6e9c7921c7
  101. function hsl2rgb($hsl){
  102.     $h = $hsl[0];
  103.     $s = $hsl[1];
  104.     $l = $hsl[2];
  105.  
  106.     $r = $g = $b = $l;
  107.     if($s <> 0){
  108.         $q = $l < 0.5 ? $l*(1+$s) : $l+$s-$l*$s;
  109.         $p = 2*$l-$q;
  110.         $r = hue2rgb($p, $q, $h+1/3);
  111.         $g = hue2rgb($p, $q, $h);
  112.         $b = hue2rgb($p, $q, $h-1/3);
  113.     }
  114.  
  115.     return array($r*255, $g*255, $b*255);
  116. }
  117.  
  118. // hue2rgb from code here: https://gist.github.com/codemasher/741f30e68c6e9c7921c7
  119. function hue2rgb($p, $q, $t){
  120.     if($t < 0) $t += 1;
  121.     if($t > 1) $t -= 1;
  122.     if($t < 1/6) return $p+($q-$p)*6*$t;
  123.     if($t < 1/2) return $q;
  124.     if($t < 2/3) return $p+($q-$p)*(2/3-$t)*6;
  125.     return $p;
  126. }
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement