Syntax Desktop PHP Cross Reference Web Portal Systems

Source: /admin/includes/php/wallpaper.php - 221 lines - 7614 bytes - Summary - Text - Print

   1  <?php
   2  include  ("../../config/cfg.php");
   3  /*

   4      Dynamic Heading Generator

   5      By Stewart Rosenberger

   6      http://www.stewartspeak.com/headings/    

   7  

   8      This script generates PNG images of text, written in

   9      the font/size that you specify. These PNG images are passed

  10      back to the browser. Optionally, they can be cached for later use. 

  11      If a cached image is found, a new image will not be generated,

  12      and the existing copy will be sent to the browser.

  13  

  14      Additional documentation on PHP's image handling capabilities can

  15      be found at http://www.php.net/image/    

  16  */
  17  $font_file  = '../../images/font/sqr721e.ttf' ;
  18  $filename = "../../".$_GET["img"];
  19  $w= $_GET["width"];
  20  $h= $_GET["height"];
  21  $text = $synWebsiteTitle ;
  22  $description="Content management system for $text website"; 
  23  $credits="Powered By SyntaxDesktop ".$synVersion; 
  24  $font_size  = 20 ;
  25  $font_size_description=10;
  26  $font_color = '#6097CC' ;
  27  $background_color = '#ffffff' ;
  28  $transparent_background  = true ;
  29  $cache_images = true ;
  30  $cache_folder = 'cache' ;
  31  //echo $font_file;

  32  //phpinfo();die;

  33  
  34  
  35  /*

  36    ---------------------------------------------------------------------------

  37     For basic usage, you should not need to edit anything below this comment.

  38     If you need to further customize this script's abilities, make sure you

  39     are familiar with PHP and its image handling capabilities.

  40    ---------------------------------------------------------------------------

  41  */
  42  @putenv('GDFONTPATH=' . realpath('../../images/font/') );
  43  
  44  $mime_type = 'image/png' ;
  45  $extension = '.png' ;
  46  $send_buffer_size = 4096 ;
  47  
  48  // check for GD support

  49  if(!function_exists('ImageCreate'))
  50      fatal_error('Error: Server does not support PHP image generation') ;
  51  
  52  // clean up text

  53  //if(empty($_GET['text']))

  54  //    fatal_error('Error: No text specified.') ;

  55  if(get_magic_quotes_gpc())
  56      $text = stripslashes($text) ;
  57  $text = javascript_to_html($text) ;
  58  
  59  // look for cached copy, send if it exists

  60  $hash = md5(basename($font_file) . $font_size . $font_color .
  61              $background_color . $transparent_background . $text) ;
  62  $cache_filename = $cache_folder . '/' . $hash . $extension ;
  63  if($cache_images && ($file = @fopen($cache_filename,'rb')))
  64  {
  65      header('Content-type: ' . $mime_type) ;
  66      while(!feof($file))
  67          print(($buffer = fread($file,$send_buffer_size))) ;
  68      fclose($file) ;
  69      exit ;
  70  }
  71  
  72  // check font availability

  73  $font_found = is_readable($font_file) ;
  74  if(!$font_found){fatal_error('Error: The server is missing the specified font.') ;}
  75  
  76  // create image

  77  $background_rgb = hex_to_rgb($background_color) ;
  78  $font_rgb = hex_to_rgb($font_color) ;
  79  $dip = get_dip($font_file,$font_size) ;
  80  $box = @ImageTTFBBox($font_size,0,$font_file,$text) ;
  81  $box2 = @ImageTTFBBox($font_size_description,0,$font_file,$description) ;
  82  $box3 = @ImageTTFBBox($font_size_description,0,$font_file,$credits) ;
  83  //$image = @ImageCreate(abs($box[2]-$box[0]),abs($box[5]-$dip)) ;

  84  
  85  
  86  // Get new dimensions

  87  list($width, $height) = getimagesize($filename);
  88  $new_width = $w;
  89  $new_height = $h;
  90  // Resample

  91  $image = imagecreatetruecolor($new_width, $new_height);
  92  $image_orig = imagecreatefromjpeg($filename);
  93  //imagecopyresampled($image, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

  94  imagecopyresized($image, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  95  
  96  //$image = imagecreatefromjpeg("blue.jpg") ;

  97  
  98  if(!$image) {
  99    //fatal_error('Error in Image: The server could not create this heading image.');

 100  }
 101  if(!$box) {//fatal_error('Error in Box: The server could not create this heading image.');
 102  } else {
 103    // allocate colors and draw text

 104    $background_color = @ImageColorAllocate($image,$background_rgb['red'],$background_rgb['green'],$background_rgb['blue']) ;
 105    $font_color = @ImageColorAllocate($image,$font_rgb['red'],$font_rgb['green'],$font_rgb['blue']) ;   
 106    $font_color_shadow = @ImageColorAllocate($image,143,197,230) ;   
 107    //ImageTTFText($image,$font_size,0,-$box[0],abs($box[5]-$box[3])-$box[1], $font_color,$font_file,$text) ;

 108    ImageTTFText($image,$font_size,0,floor($w/2)-floor($box[4]/2)+1,floor($h/2)-floor($box[5]/2)+1, $font_color_shadow, $font_file,$text) ;
 109    ImageTTFText($image,$font_size,0,floor($w/2)-floor($box[4]/2),floor($h/2)-floor($box[5]/2), $font_color,$font_file,$text) ;
 110    ImageTTFText($image,$font_size_description,0,floor($w/2)-floor($box2[4]/2)+1,floor($h/2)-floor($box2[5]/2)+20, $font_color, $font_file,$description) ;
 111    ImageTTFText($image,$font_size_description,0,floor($w/2)-floor($box3[4]/2)+1,floor($h/2)-floor($box3[5]/2)+33, $font_color, $font_file,$credits) ;
 112    // set transparency

 113    if($transparent_background) ImageColorTransparent($image,$background_color) ;
 114  }
 115        
 116  header('Content-type: ' . $mime_type) ;
 117  ImagePNG($image) ;
 118  
 119  // save copy of image for cache

 120  if($cache_images)
 121  {
 122      @ImagePNG($image,$cache_filename) ;
 123  }
 124  
 125  ImageDestroy($image) ;
 126  exit ;
 127  
 128  
 129  /*

 130      try to determine the "dip" (pixels dropped below baseline) of this

 131      font for this size.

 132  */
 133  function get_dip($font,$size)
 134  {
 135      $test_chars = 'abcdefghijklmnopqrstuvwxyz' .
 136                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
 137                    '1234567890' .
 138                    '!@#$%^&*()\'"\\/;.,`~<>[]{}-+_-=' ;
 139      $box = @ImageTTFBBox($size,0,$font,$test_chars) ;
 140      return $box[3] ;
 141  }
 142  
 143  
 144  /*

 145      attempt to create an image containing the error message given. 

 146      if this works, the image is sent to the browser. if not, an error

 147      is logged, and passed back to the browser as a 500 code instead.

 148  */
 149  function fatal_error($message)
 150  {
 151      // send an image

 152      if(function_exists('ImageCreate'))
 153      {
 154          $width = ImageFontWidth(5) * strlen($message) + 20 ;
 155          $height = ImageFontHeight(5) + 10 ;
 156          if($image = ImageCreate($width,$height))
 157          {
 158              $background = ImageColorAllocate($image,255,255,255) ;
 159              $text_color = ImageColorAllocate($image,0,0,0) ;
 160              ImageString($image,5,5,5,$message,$text_color) ;    
 161              header('Content-type: image/png') ;
 162              ImagePNG($image) ;
 163              ImageDestroy($image) ;
 164              exit ;
 165          }
 166      }
 167  
 168      // send 500 code

 169      header("HTTP/1.0 500 Internal Server Error") ;
 170      print($message) ;
 171      exit ;
 172  }
 173  
 174  
 175  /* 

 176      decode an HTML hex-code into an array of R,G, and B values.

 177      accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff 

 178  */    
 179  function hex_to_rgb($hex)
 180  {
 181      // remove '#'

 182      if(substr($hex,0,1) == '#')
 183          $hex = substr($hex,1) ;
 184  
 185      // expand short form ('fff') color

 186      if(strlen($hex) == 3)
 187      {
 188          $hex = substr($hex,0,1) . substr($hex,0,1) .
 189                 substr($hex,1,1) . substr($hex,1,1) .
 190                 substr($hex,2,1) . substr($hex,2,1) ;
 191      }
 192  
 193      if(strlen($hex) != 6)
 194          fatal_error('Error: Invalid color "'.$hex.'"') ;
 195  
 196      // convert

 197      $rgb['red'] = hexdec(substr($hex,0,2)) ;
 198      $rgb['green'] = hexdec(substr($hex,2,2)) ;
 199      $rgb['blue'] = hexdec(substr($hex,4,2)) ;
 200  
 201      return $rgb ;
 202  }
 203  
 204  
 205  /*

 206      convert embedded, javascript unicode characters into embedded HTML

 207      entities. (e.g. '%u2018' => '&#8216;'). returns the converted string.

 208  */
 209  function javascript_to_html($text)
 210  {
 211      $matches = null ;
 212      preg_match_all('/%u([0-9A-F]{4})/i',$text,$matches) ;
 213      if(!empty($matches)) for($i=0;$i<sizeof($matches[0]);$i++)
 214          $text = str_replace($matches[0][$i],
 215                              '&#'.hexdec($matches[1][$i]).';',$text) ;
 216  
 217      return $text ;
 218  }
 219  
 220  ?>
 221  

title

Description

title

Description

title

Description

title

title

Body