ferrybig

random avatar

Jun 4th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.06 KB | None | 0 0
  1. $gd = imagecreate(120, 120);
  2.         $code = str_baseconvert(md5("image_shape_salt_" + $id), 16, 8);
  3.         $color = str_baseconvert(md5("image_color_salt_" + $id), 16, 36);
  4.         $background = imagecolorallocatealpha($gd, 255, 255, 255, 0);
  5.         $maincolor = imagecolorallocate($gd, base_convert($color[0], 36, 10) * 10 + 100, base_convert($color[1], 36, 10) * 10 + 100, base_convert($color[2], 36, 10) * 10 + 100);
  6.         for ($x = 0; $x < 4; $x++) {
  7.             for ($z = 0; $z < 4; $z++) {
  8.                 $number = (int) $code[$x * 4 + $z];
  9.                 switch ($number) {
  10.                     case 0:
  11.                         break;
  12.                     case 1: // Full square
  13.                         imagefilledrectangle($gd, $x * 30, $z * 30, $x * 30 + 29, $z * 30 + 29, $maincolor);
  14.                         break;
  15.                     case 2: // top
  16.                         imagefilledrectangle($gd, $x * 30, $z * 30, $x * 30 + 14, $z * 30 + 29, $maincolor);
  17.                         break;
  18.                     case 3: // left
  19.                         imagefilledrectangle($gd, $x * 30, $z * 30, $x * 30 + 29, $z * 30 + 14, $maincolor);
  20.                         break;
  21.                     case 4: // bottom
  22.                         imagefilledrectangle($gd, $x * 30 + 15, $z * 30, $x * 30 + 29, $z * 30 + 29, $maincolor);
  23.                         break;
  24.                     case 5: // right
  25.                         imagefilledrectangle($gd, $x * 30, $z * 30 + 15, $x * 30 + 29, $z * 30 + 29, $maincolor);
  26.                         break;
  27.                     case 6: // middle
  28.                         imagefilledrectangle($gd, $x * 30 + 5, $z * 30 + 5, $x * 30 + 24, $z * 30 + 24, $maincolor);
  29.                         break;
  30.                     case 7: // hollow
  31.                         imagefilledrectangle($gd, $x * 30, $z * 30, $x * 30 + 29, $z * 30 + 29, $maincolor);
  32.                         imagefilledrectangle($gd, $x * 30 + 7, $z * 30 + 7, $x * 30 + 22, $z * 30 + 22, $background);
  33.                         break;
  34.                 }
  35.             }
  36.         }
  37.         $pattern = imagecreate(60, 60);
  38.         imagecopyresized($pattern, $gd, 0, 0, 0, 0, 60, 60, 120, 120);
  39.         imagecopy($gd, $pattern, 0, 0, 0, 0, 60, 60);
  40.         imageflip($pattern, IMG_FLIP_HORIZONTAL);
  41.         imagecopy($gd, $pattern, 60, 0, 0, 0, 60, 60);
  42.         imageflip($pattern, IMG_FLIP_VERTICAL);
  43.         imagecopy($gd, $pattern, 60, 60, 0, 0, 60, 60);
  44.         imageflip($pattern, IMG_FLIP_HORIZONTAL);
  45.         imagecopy($gd, $pattern, 0, 60, 0, 0, 60, 60);
  46.         imagedestroy($pattern);
  47.         imagepng($gd);
  48.         imagedestroy($gd);
Advertisement
Add Comment
Please, Sign In to add comment