Advertisement
comicidiot

Strax Quote Image Generator

Mar 22nd, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.91 KB | None | 0 0
  1. <?php
  2. #   error_reporting(E_ALL);
  3.    
  4.     // While I coded this Drax quote thing, I doubt it's original and I'm sure others exist
  5.     // But this one is mine.
  6.     ## Alex Glanville 2015 - March 21st - http://comicidiot.com/strax.jpg
  7.     ## Inspired by a TI-84+CSE program my friend Daniel, tifreak, created
  8.  
  9.    
  10.     // Copied this fucntion from
  11.     // http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/
  12.         function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
  13.             for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
  14.                 for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
  15.                     $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
  16.          
  17.            return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
  18.         }
  19.    
  20.     // We'll use this for a section below where we need to determine if the first letter is a vowel
  21.         $vowel      = "/^[aeiou]/";
  22.         $font       = "res/monof55.ttf";
  23.         $imgloc     = "res/strax_bg.jpg";
  24.         $fontsize   = 12;
  25.         $StraxIMG   = imagecreatefromjpeg($imgloc);
  26.        
  27.     // Set this early so we don't get an error later on
  28.         $six        = null;
  29.  
  30.     // This is part 2 because it's effecively the second part of the string.
  31.     // We need to get this first so we can either display "a" or "an" based
  32.     // on the first letter of the selected phrase.
  33.     ## Begin part 2
  34.         $part       =   array(
  35.             "full-frontal",
  36.             "pincer",
  37.             "surprise",
  38.             "brutally excessive",
  39.             "suicide",
  40.             "multi-pronged",
  41.             "glorious",
  42.             "acid-heavy",
  43.             "immediate",
  44.             "violent",
  45.             "traditional Sontaran",
  46.             "devasting");
  47.        
  48.         $select     =   rand(0,(count($part)-1));
  49.         $two        =   $part[$select];
  50.    
  51.     ## Begin Part 1
  52.         if(preg_match($vowel, $two)) {
  53.             $one    = "an";
  54.         } else {
  55.             $one    = "a";
  56.         }
  57.        
  58.     ## Begin Part 3
  59.         $part       =   array(
  60.             "assault",
  61.             "attack",
  62.             "bombardment",
  63.             "offensive",
  64.             "barrage",
  65.             "charge",
  66.             "strike",
  67.             "operation",
  68.             "manoeuvre");
  69.  
  70.         $select     =   rand(0,(count($part)-1));
  71.         $three      =   $part[$select];
  72.        
  73.     ## Begin Part 4
  74.         $four       =   "with";
  75.        
  76.     ## Begin Part 5
  77.         $part       =   array(
  78.             "laser",
  79.             "berserker",
  80.             "acid",
  81.             "armoured attack",
  82.             "proton",
  83.             "three kinds of",
  84.             "atomic",
  85.             "toxic",
  86.             "explosive",
  87.             "red-hot",
  88.             "thermal",
  89.             "automated fire",
  90.             "cluster",
  91.             "enhanced germ",
  92.             "energy-drink-fueled");
  93.  
  94.         $select     =   rand(0,(count($part)-1));
  95.         $five       =   $part[$select];
  96.        
  97.     ## Begin Part 6
  98.     // Since acid appears in both $five and $six here, let's set up a check so
  99.     // the phrase "acid acid" doesn't appear.
  100.  
  101.             $part       =   array(
  102.                 "bees",
  103.                 "chainsaws",
  104.                 "marmots",
  105.                 "acid",
  106.                 "monkeys",
  107.                 "mines",
  108.                 "bombs",
  109.                 "snakes",
  110.                 "spiders",
  111.                 "knives",
  112.                 "rockets",
  113.                 "sharks",
  114.                 "owls",
  115.                 "repurposed cybermats",
  116.                 "cannons",
  117.                 "alligators");
  118.                
  119.             $select         =       rand(0,(count($part)-1));
  120.             $six            =       $part[$select];
  121.            
  122.             while($six == $five) {
  123.                     $select         =       rand(0,(count($part)-1));
  124.                     $six            =       $part[$select];
  125.             }
  126.        
  127. #   if("$five $six" == "acid acid") {$five = "highly acidic";}
  128.        
  129.     ## Begin Part 7
  130.         $seven      =   "and";
  131.        
  132.     ## Begin Part 8
  133.         $part       =   array(
  134.             "robots",
  135.             "ninjas",
  136.             "grenades",
  137.             "a dolphin full of napalm",
  138.             "acid",
  139.             "dynamite",
  140.             "xenomorphs",
  141.             "lots and lots of C4",
  142.             "tactical nukes",
  143.             "MacGyver",
  144.             "bio-weapons",
  145.             "rocket launchers",
  146.             "an elephant",
  147.             "a memory worm for afterwards",
  148.             "this pencil");
  149.  
  150.         $select     =   rand(0,(count($part)-1));
  151.         $eight      =   $part[$select];
  152.        
  153.         $string1        =   "Might I suggest $one $two";
  154.         $string2        =   "$three $four $five $six";
  155.         $string3        =   "$seven $eight?";
  156.     ## This is the longest the string can be. Uncomment the line below to make sure your image is long enough
  157.     ## This is kinda of not required since I abandonded the single string idea, but I'll leave it in for posterity.
  158.     ##  $string     =   "An traditional Sontaran bombardment with energy-drink-fuelled reporposed cybermats and a memory worm for afterwards";
  159.  
  160.     ## Create the image!
  161.         list($width, $height, $type, $attr)     = getimagesize($imgloc);
  162.         $white = imagecolorallocate($StraxIMG, 255, 255, 255);
  163.         $black = imagecolorallocate($StraxIMG, 0, 0, 0);
  164.  
  165.         #imagestring($StraxIMG, $font, 0, 0, $string, $color);
  166.         imagettfstroketext($StraxIMG, $fontsize, 0, 80, 20, $white, $black, $font, $string1, 1);
  167.         imagettfstroketext($StraxIMG, $fontsize, 0, 100, 40, $white, $black, $font, $string2, 1);
  168.         imagettfstroketext($StraxIMG, $fontsize, 0, 120, 60, $white, $black, $font, $string3, 1);
  169. #       imagettftext($StraxIMG, 10, 0, 80, 40, $black, $font,$string);
  170.                
  171.         // Set the content type header - in this case image/jpeg
  172.         header('Content-Type: image/jpeg');
  173.        
  174.         // Output the image
  175.         imagejpeg($StraxIMG);
  176.        
  177.         // Free up memory
  178.         imagedestroy($StraxIMG);
  179.    
  180. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement