rzdev / countdown-gif
Countdown-Gif generator
dev-master
2020-01-16 10:14 UTC
Requires
- php: ^7.0
- ext-imagick: *
- cache/adapter-common: ^1.0
- psr/cache: ^1.0
Suggests
- cache/filesystem-adapter: Allows to cache single frames in filesystem
- cache/memcache-adapter: Allows to cache single frames in memcache
- cache/memcached-adapter: Allows to cache single frames in memcached
- cache/predis-adapter: Allows to cache single frames in predis
- cache/redis-adapter: Allows to cache single frames in redis
This package is not auto-updated.
Last update: 2025-03-08 09:32:26 UTC
README
$request = \Illuminate\Http\Request::createFromGlobals(); $timezone = timezone_open((string) $request->get('tz', 'Europe/Berlin')); $now = new DateTime('now', $timezone); $target = new DateTime($request->get('t', 'now'), $timezone); $runtime = max(0, min(300, $request->get('r', 10))); $default = $request->get('d'); $format = $request->get('f', '{d}:{h}:{m}:{s}'); $width = intval($request->get('w', 500)); $height = intval($request->get('h', 50)); $bgColor = '#'.$request->get('bg', 'ffffff'); $fontType = $request->get('ft'); $fontSize = intval($request->get('fs', 48)); $fontColor = $request->get('fc', '#ff0000'); $formatter = new \Astrotomic\CountdownGif\Helper\Formatter($format); $background = new Imagick(); $background->setFormat('png'); $background->newImage($width, $height, $bgColor); $font = new \Astrotomic\CountdownGif\Helper\Font($fontType, $fontSize, $fontColor, [ 'lato' => resource_path('lato-regular.ttf'), ]); $redis = new \Redis(); $config = app('config')->get('database.redis.default'); $redis->connect($config['host'], $config['port']); $redisPool = new \Cache\Adapter\Redis\RedisCachePool($redis); $countDownGif = new \Astrotomic\CountdownGif\CountdownGif($now, $target, $runtime, $formatter, $background, $font, $default, $redisPool, \Cache\Adapter\Common\CacheItem::class); $gif = $countDownGif->generate($background->getImageWidth() / 2, $background->getImageHeight() / 2); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header('Content-Type: image/gif'); echo $gif->getImagesBlob();