Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- define('JUMPS', 10);
- define('DURATIONPERFRAME', 10);
- include('classes/gif.php');
- $model = json_decode($_POST['data']);
- $colors = array(
- 'brown' => array(
- 165,
- 42,
- 42
- ),
- 'cadetblue' => array(
- 95,
- 158,
- 160
- ),
- 'chartreuse' => array(
- 127,
- 255,
- 0
- ),
- 'chocolate' => array(
- 210,
- 105,
- 30
- ),
- 'coral' => array(
- 255,
- 127,
- 80
- ),
- 'crimson' => array(
- 220,
- 20,
- 60
- )
- );
- $dir = uniqid() . mt_rand();
- $dire = $dir;
- mkdir($dir);
- $dir .= '/';
- $durations = [];
- $frames = [];
- $length = count($model);
- for ($j = JUMPS; $j < $length; $j += JUMPS) {
- $img = @imagecreatefromgif('images/base.gif');
- for ($i = 0; $i <= $j; $i++) {
- $colorName = $model[$i]->color;
- $color = imagecolorallocate($img, $colors[$colorName][0] ,$colors[$colorName][1] , $colors[$colorName][2]);
- imagefilledellipse($img, $model[$i]->x, $model[$i]->y, $model[$i]->radius * 2, $model[$i]->radius * 2, $color);
- }
- imagegif($img, $dir . $j . '.gif', 9);
- imagedestroy($img);
- $durations[] = DURATIONPERFRAME;
- $frames[] = $dir . $j . '.gif';
- }
- $length %= JUMPS;
- $length += $j - JUMPS;
- $img = @imagecreatefromgif('images/base.gif');
- for ($i = 0; $i < $length; $i++) {
- $colorName = $model[$i]->color;
- $color = imagecolorallocate($img, $colors[$colorName][0] ,$colors[$colorName][1] , $colors[$colorName][2]);
- imagefilledellipse($img, $model[$i]->x, $model[$i]->y, $model[$i]->radius * 2, $model[$i]->radius * 2, $color);
- }
- imagegif($img, $dir . $j . '.gif', 9);
- imagedestroy($img);
- $durations[] = DURATIONPERFRAME;
- $frames[] = $dir . $j . '.gif';
- $durations[count($durations) - 1] = 100;
- $gc = new GifCreator();
- $gc->create($frames, $durations, 0);
- $gifBinary = $gc->getGif();
- file_put_contents('a.gif', $gifBinary);
- $files = glob("$dir*");
- foreach ($files as $file)
- unlink($file);
- rmdir($dire);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement