Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL & ~ E_NOTICE & ~ E_STRICT & ~ E_DEPRECATED & ~ E_WARNING);
- setlocale(LC_ALL,"en_US.UTF-8");
- $query = $_GET['query'];
- if (! empty($_GET['base64']))
- $query = base64_decode($_GET['base64']);
- $query = trim($query, '/');
- $queryString = $query;
- $query = explode('/', $query);
- $query = array_filter($query);
- $keys = $values = array();
- foreach ($query as $key => $value)
- {
- if ($key & 1)
- $values[] = $value;
- else
- $keys[] = $value;
- }
- $query = array_combine($keys, $values);
- $cache = (bool)$query['cache'];
- unset($query['cache']);
- $cachePath = 'static/cache/%s';
- $cacheTag = sha1($queryString);
- $cacheFile = sprintf($cachePath, $cacheTag) . '.png';
- if (file_exists($cacheFile) AND ! $query['cache'] AND 1 == 0)
- {
- header('Content-Type: image/png');
- readfile($cacheFile);
- exit(1);
- }
- $fontPath = 'static/fonts/%s.ttf';
- $fontFile = $query['family'];
- if (empty($fontFile) or ! file_exists(sprintf($fontPath, $fontFile)))
- $fontFile = 'Lobster';
- $fontFile = sprintf($fontPath, $fontFile);
- $text = $query['text'];
- if (empty($text))
- $text = 'Raska';
- $text = stripslashes($text);
- $color = $query['color'];
- if (preg_match('/^#?([0-9a-f]{6})$/i', $color, $matches))
- $rgb = $matches[1];
- else
- $color = 'CC0000';
- $fontSize = $query['size'];
- if (! filter_var($fontSize, FILTER_VALIDATE_INT))
- $fontSize = 36;
- if( !empty($query['color_1']) AND ! empty($query['color_2']))
- {
- $color = "-fill gradient:'#{$query[color_1]}-#{$query[color_2]}'";
- }
- else
- {
- $color = "-fill '#$color'";
- }
- $textLayer = "( -background none $color -font '$fontFile' -pointsize $fontSize label:'$text' )";
- $dropShadow = '';
- if( ! empty($query['shadow']))
- {
- $dropShadow = "( -background none -fill black -font '$fontFile' -pointsize $fontSize label:'$text' -geometry +0+2 ) -compose dstover -composite";
- }
- execute("convert $textLayer $dropShadow '$cacheFile'");
- header('Content-Type: image/png');
- readfile($cacheFile);
- function execute($command)
- {
- #echo $command; die;
- # remove newlines and convert single quotes to double to prevent errors
- $command = str_replace(array("\n", "'", '(', ')'), array('', '"', '\(', '\)'), $command);
- # replace multiple spaces with one
- $command = preg_replace('#(\s){2,}#is', ' ', $command);
- # escape shell metacharacters
- #$command = escapeshellcmd($command);
- #echo $command; die;
- # execute convert program
- return shell_exec($command);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement