Advertisement
erinx

generate stack images

Sep 17th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.22 KB | None | 0 0
  1. function genstacks($a){
  2.    
  3.   $a = intval($a);
  4.    
  5.   $stackpath = 'stacks/';
  6.  
  7.   function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px){
  8.     for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
  9.     for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
  10.     $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
  11.     return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
  12.   }
  13.  
  14.  
  15.   $cs = intval(intval($a)/10000);
  16.   $cr = intval(intval($a)%10000);
  17.  
  18.   $ps = intval(intval($cr)/100);
  19.  
  20.   $gs = intval(intval($cr)%100);
  21.  
  22.   $stackWidth = 2;
  23.  
  24.   if($cs > 100){
  25.     $cu = $cs;
  26.     while($cu > 100){
  27.       $stackWidth += 34;
  28.       $cu = $cu-100;
  29.     }
  30.     if($cu >= 1){
  31.       $stackWidth += 34;
  32.     }
  33.   }else if($cs >= 1){
  34.     $stackWidth += 34;
  35.   }
  36.  
  37.   if($ps >= 1){
  38.     $stackWidth += 34;
  39.   }
  40.  
  41.   if($gs >= 1){
  42.     $stackWidth += 34;
  43.   }
  44.  
  45.  
  46.   $img = imagecreatetruecolor($stackWidth, 32);
  47.  
  48.   imagesavealpha($img, true);
  49.  
  50.   $trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
  51.   imagefill($img, 0, 0, $trans_colour);
  52.  
  53.   $stroke_color = imagecolorallocate($img, 0, 0, 0);
  54.   $text_color = imagecolorallocate($img, 255, 255, 255);
  55.  
  56.   $xPosition = 2;
  57.  
  58.   if($cs > 100){
  59.     $cu = $cs;
  60.     $ci = '';
  61.     while($cu > 100){
  62.       $src = imagecreatefrompng($stackpath . 'c-50-100.png');
  63.       imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  64.       imagettfstroketext($img, 8, 0, $xPosition + 9, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", 100, 1);
  65.       $xPosition += 34;
  66.       $cu = $cu-100;
  67.     }
  68.     if($cu >= 50){
  69.      $src = imagecreatefrompng($stackpath . 'c-50-100.png');
  70.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  71.      if($cu == 100){
  72.        imagettfstroketext($img, 8, 0, $xPosition + 9, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  73.      }else{
  74.        imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  75.      }
  76.      $xPosition += 34;
  77.     }else if($cu >= 25){
  78.      $src = imagecreatefrompng($stackpath . 'c-25-49.png');
  79.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  80.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  81.      $xPosition += 34;
  82.     }else if($cu >= 10){
  83.       $src = imagecreatefrompng($stackpath . 'c-10-24.png');
  84.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  85.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  86.      $xPosition += 34;
  87.     }else if($cu >= 5){
  88.      $src = imagecreatefrompng($stackpath . 'c-5-9.png');
  89.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  90.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  91.      $xPosition += 34;
  92.     }else if($cu == 4){
  93.      $src = imagecreatefrompng($stackpath . 'c-4.png');
  94.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  95.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  96.      $xPosition += 34;
  97.     }else if($cu == 3){
  98.       $src = imagecreatefrompng($stackpath . 'c-3.png');
  99.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  100.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  101.      $xPosition += 34;
  102.     }else if($cu == 2){
  103.      $src = imagecreatefrompng($stackpath . 'c-2.png');
  104.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  105.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  106.      $xPosition += 34;
  107.     }else if($cu == 1){
  108.      $src = imagecreatefrompng($stackpath . 'c-1.png');
  109.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  110.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cu, 1);
  111.      $xPosition += 34;
  112.     }
  113.   }else if($cs >= 50){
  114.      $src = imagecreatefrompng($stackpath . 'c-50-100.png');
  115.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  116.      if($cs == 100){
  117.        imagettfstroketext($img, 8, 0, $xPosition + 9, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  118.      }else{
  119.        imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  120.      }
  121.      $xPosition += 34;
  122.   }else if($cs >= 25){
  123.      $src = imagecreatefrompng($stackpath . 'c-25-49.png');
  124.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  125.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  126.      $xPosition += 34;
  127.   }else if($cs >= 10){
  128.       $src = imagecreatefrompng($stackpath . 'c-10-24.png');
  129.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  130.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  131.      $xPosition += 34;
  132.   }else if($cs >= 5){
  133.      $src = imagecreatefrompng($stackpath . 'c-5-9.png');
  134.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  135.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  136.      $xPosition += 34;
  137.   }else if($cs == 4){
  138.      $src = imagecreatefrompng($stackpath . 'c-4.png');
  139.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  140.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  141.      $xPosition += 34;
  142.   }else if($cs == 3){
  143.       $src = imagecreatefrompng($stackpath . 'c-3.png');
  144.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  145.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  146.      $xPosition += 34;
  147.   }else if($cs == 2){
  148.      $src = imagecreatefrompng($stackpath . 'c-2.png');
  149.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  150.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  151.      $xPosition += 34;
  152.   }else if($cs == 1){
  153.      $src = imagecreatefrompng($stackpath . 'c-1.png');
  154.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  155.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $cs, 1);
  156.      $xPosition += 34;
  157.   }
  158.  
  159.   if($ps >= 50){
  160.      $src = imagecreatefrompng($stackpath . 'p-50-100.png');
  161.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  162.      if($ps == 100){
  163.        imagettfstroketext($img, 8, 0, $xPosition + 9, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  164.      }else{
  165.        imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  166.      }
  167.      $xPosition += 34;
  168.   }else if($ps >= 25){
  169.      $src = imagecreatefrompng($stackpath . 'p-25-49.png');
  170.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  171.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  172.      $xPosition += 34;
  173.   }else if($ps >= 10){
  174.       $src = imagecreatefrompng($stackpath . 'p-10-24.png');
  175.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  176.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  177.      $xPosition += 34;
  178.   }else if($ps >= 5){
  179.      $src = imagecreatefrompng($stackpath . 'p-5-9.png');
  180.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  181.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  182.      $xPosition += 34;
  183.   }else if($ps == 4){
  184.      $src = imagecreatefrompng($stackpath . 'p-4.png');
  185.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  186.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  187.      $xPosition += 34;
  188.   }else if($ps == 3){
  189.       $src = imagecreatefrompng($stackpath . 'p-3.png');
  190.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  191.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  192.      $xPosition += 34;
  193.   }else if($ps == 2){
  194.      $src = imagecreatefrompng($stackpath . 'p-2.png');
  195.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  196.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  197.      $xPosition += 34;
  198.   }else if($ps == 1){
  199.      $src = imagecreatefrompng($stackpath . 'p-1.png');
  200.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  201.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $ps, 1);
  202.      $xPosition += 34;
  203.   }
  204.  
  205.   if($gs >= 50){
  206.      $src = imagecreatefrompng($stackpath . 'g-50-100.png');
  207.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  208.      if($gs == 100){
  209.        imagettfstroketext($img, 8, 0, $xPosition + 9, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  210.      }else{
  211.        imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  212.      }
  213.      $xPosition += 34;
  214.   }else if($gs >= 25){
  215.      $src = imagecreatefrompng($stackpath . 'g-25-49.png');
  216.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  217.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  218.      $xPosition += 34;
  219.   }else if($gs >= 10){
  220.       $src = imagecreatefrompng($stackpath . 'g-10-24.png');
  221.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  222.      imagettfstroketext($img, 8, 0, $xPosition + 17, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  223.      $xPosition += 34;
  224.   }else if($gs >= 5){
  225.      $src = imagecreatefrompng($stackpath . 'g-5-9.png');
  226.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  227.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  228.      $xPosition += 34;
  229.   }else if($gs == 4){
  230.      $src = imagecreatefrompng($stackpath . 'g-4.png');
  231.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  232.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  233.      $xPosition += 34;
  234.   }else if($gs == 3){
  235.       $src = imagecreatefrompng($stackpath . 'g-3.png');
  236.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  237.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  238.      $xPosition += 34;
  239.   }else if($gs == 2){
  240.      $src = imagecreatefrompng($stackpath . 'g-2.png');
  241.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  242.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  243.      $xPosition += 34;
  244.   }else if($gs == 1){
  245.      $src = imagecreatefrompng($stackpath . 'g-1.png');
  246.      imagecopy($img, $src, $xPosition, 0, 0, 0, 32, 32);
  247.      imagettfstroketext($img, 8, 0, $xPosition + 23, 30, $text_color, $stroke_color, "Tahoma_Bold.ttf", $gs, 1);
  248.      $xPosition += 34;
  249.   }
  250.  
  251.  
  252.   imagepng($img, "coinstacks.png");
  253.  
  254.   imagecolordeallocate($img, $line_color);
  255.   imagecolordeallocate($img, $text_color);  
  256.   imagecolordeallocate($img, $trans_colour);
  257.   imagedestroy($img);
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement