Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1. <?php
  2.     set_time_limit(0);
  3.     define('JUMPS', 10);
  4.     define('DURATIONPERFRAME', 10);
  5.     include('classes/gif.php');
  6.     $model = json_decode($_POST['data']);
  7.     $colors = array(
  8.         'brown' => array(
  9.             165,
  10.             42,
  11.             42
  12.         ),
  13.         'cadetblue' => array(
  14.             95,
  15.             158,
  16.             160
  17.         ),
  18.         'chartreuse' => array(
  19.             127,
  20.             255,
  21.             0
  22.         ),
  23.         'chocolate' => array(
  24.             210,
  25.             105,
  26.             30
  27.         ),
  28.         'coral' => array(
  29.             255,
  30.             127,
  31.             80
  32.         ),
  33.         'crimson' => array(
  34.             220,
  35.             20,
  36.             60
  37.         )
  38.     );
  39.  
  40.     $dir = uniqid() . mt_rand();
  41.     $dire = $dir;
  42.     mkdir($dir);
  43.     $dir .= '/';
  44.     $durations = [];
  45.     $frames = [];
  46.     $length = count($model);
  47.     for ($j = JUMPS; $j < $length; $j += JUMPS) {
  48.         $img = @imagecreatefromgif('images/base.gif');
  49.  
  50.         for ($i = 0; $i <= $j; $i++) {
  51.             $colorName = $model[$i]->color;
  52.             $color = imagecolorallocate($img, $colors[$colorName][0] ,$colors[$colorName][1] , $colors[$colorName][2]);
  53.             imagefilledellipse($img, $model[$i]->x, $model[$i]->y, $model[$i]->radius * 2, $model[$i]->radius * 2, $color);
  54.         }
  55.         imagegif($img, $dir . $j . '.gif', 9);
  56.         imagedestroy($img);
  57.         $durations[] = DURATIONPERFRAME;
  58.         $frames[] = $dir . $j . '.gif';
  59.     }
  60.     $length %= JUMPS;
  61.     $length += $j - JUMPS;
  62.  
  63.     $img = @imagecreatefromgif('images/base.gif');
  64.     for ($i = 0; $i < $length; $i++) {
  65.         $colorName = $model[$i]->color;
  66.  
  67.         $color = imagecolorallocate($img, $colors[$colorName][0] ,$colors[$colorName][1] , $colors[$colorName][2]);
  68.         imagefilledellipse($img, $model[$i]->x, $model[$i]->y, $model[$i]->radius * 2, $model[$i]->radius * 2, $color);
  69.     }
  70.     imagegif($img, $dir . $j . '.gif', 9);
  71.     imagedestroy($img);
  72.     $durations[] = DURATIONPERFRAME;
  73.     $frames[] = $dir . $j . '.gif';
  74.  
  75.     $durations[count($durations) - 1] = 100;
  76.         $gc = new GifCreator();
  77.         $gc->create($frames, $durations, 0);
  78.         $gifBinary = $gc->getGif();
  79.         file_put_contents('a.gif', $gifBinary);
  80.     $files = glob("$dir*");
  81.     foreach ($files as $file)
  82.         unlink($file);
  83.     rmdir($dire);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement