topical media & game development

talk show tell print

professional-search-10-seophp-fortune-cookie.php / php



  <?php
  
  class Fortunes
  {
    // Array with possible fortune predictions
    var _fortunes = array(
      "Jaimie Sirovich will become your\r\nfavorite author.",
      "You will recommend this book to\r\nall your friends.",
      "Tomorrow you will make \r\nyour first million.",
      "You will read AJAX and PHP: \r\nBuilding Responsive Web Applications."
    ); 
    
    // Member that will the generated image
    var _image_resource;
  
    // Generate fortune cookie image
    function MakeFortune()
    {
      text = this->_fortunes[rand(0, sizeof(this->_fortunes) - 1)];
      this->_image_resource = imagecreatefromgif('images/fortune_cookie.gif');    
      imagettftext(this->_image_resource, 9, 0, 135, 64, 
                  imagecolorallocate(this->_image_resource, 0, 0, 0), 
                  'fonts/comic.ttf', text);
      imagegif(this->_image_resource);
    }  
  }
  
  // Set proper content type for GIF image
  header('Content-type: image/gif'); 
  
  // Generate the GIF image
  f = new Fortunes();
  f->MakeFortune();
  
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.