Advertisement
webarto

Untitled

Dec 14th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL & ~ E_NOTICE & ~ E_STRICT & ~ E_DEPRECATED & ~ E_WARNING);
  4.  
  5. setlocale(LC_ALL,"en_US.UTF-8");
  6.  
  7. $query = $_GET['query'];
  8. if (! empty($_GET['base64']))
  9.   $query = base64_decode($_GET['base64']);
  10.  
  11. $query = trim($query, '/');
  12. $queryString = $query;
  13. $query = explode('/', $query);
  14. $query = array_filter($query);
  15.  
  16. $keys = $values = array();
  17. foreach ($query as $key => $value)
  18. {
  19.   if ($key & 1)
  20.     $values[] = $value;
  21.   else
  22.     $keys[] = $value;
  23. }
  24. $query = array_combine($keys, $values);
  25.  
  26. $cache = (bool)$query['cache'];
  27. unset($query['cache']);
  28.  
  29. $cachePath = 'static/cache/%s';
  30. $cacheTag = sha1($queryString);
  31. $cacheFile = sprintf($cachePath, $cacheTag) . '.png';
  32.  
  33. if (file_exists($cacheFile) AND ! $query['cache'] AND 1 == 0)
  34. {
  35.   header('Content-Type: image/png');
  36.   readfile($cacheFile);
  37.   exit(1);
  38. }
  39.  
  40. $fontPath = 'static/fonts/%s.ttf';
  41.  
  42. $fontFile = $query['family'];
  43. if (empty($fontFile) or ! file_exists(sprintf($fontPath, $fontFile)))
  44.   $fontFile = 'Lobster';
  45. $fontFile = sprintf($fontPath, $fontFile);
  46.  
  47. $text = $query['text'];
  48. if (empty($text))
  49.   $text = 'Raska';
  50.  
  51. $text = stripslashes($text);
  52.  
  53. $color = $query['color'];
  54. if (preg_match('/^#?([0-9a-f]{6})$/i', $color, $matches))
  55.   $rgb = $matches[1];
  56. else
  57.   $color = 'CC0000';
  58.  
  59. $fontSize = $query['size'];
  60. if (! filter_var($fontSize, FILTER_VALIDATE_INT))
  61.   $fontSize = 36;
  62.  
  63. if( !empty($query['color_1']) AND ! empty($query['color_2']))
  64. {
  65.   $color = "-fill gradient:'#{$query[color_1]}-#{$query[color_2]}'";
  66. }
  67. else
  68. {
  69.   $color = "-fill '#$color'";
  70. }
  71.  
  72. $textLayer = "( -background none $color -font '$fontFile' -pointsize $fontSize label:'$text' )";
  73. $dropShadow = '';
  74. if( ! empty($query['shadow']))
  75. {
  76.   $dropShadow = "( -background none -fill black -font '$fontFile' -pointsize $fontSize label:'$text' -geometry +0+2 ) -compose dstover -composite";
  77. }
  78. execute("convert $textLayer $dropShadow '$cacheFile'");
  79.  
  80. header('Content-Type: image/png');
  81. readfile($cacheFile);
  82.  
  83. function execute($command)
  84. {
  85.   #echo $command; die;
  86.  # remove newlines and convert single quotes to double to prevent errors
  87.  $command = str_replace(array("\n", "'", '(', ')'), array('', '"', '\(', '\)'), $command);
  88.   # replace multiple spaces with one
  89.  $command = preg_replace('#(\s){2,}#is', ' ', $command);
  90.   # escape shell metacharacters
  91.  #$command = escapeshellcmd($command);
  92.  #echo $command; die;
  93.  # execute convert program
  94.  return shell_exec($command);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement