[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wysiwyg/shared/tiny_mce/plugins/ibrowser/scripts/phpThumb/demo/ -> phpThumb.demo.object.php (source)

   1  <?php
   2  //////////////////////////////////////////////////////////////
   3  ///  phpThumb() by James Heinrich <info@silisoftware.com>   //
   4  //        available at http://phpthumb.sourceforge.net     ///
   5  //////////////////////////////////////////////////////////////
   6  ///                                                         //
   7  // phpThumb.demo.object.php                                 //
   8  // James Heinrich <info@silisoftware.com>                   //
   9  //                                                          //
  10  // Example of how to use phpthumb.class.php as an object    //
  11  //                                                          //
  12  //////////////////////////////////////////////////////////////
  13  
  14  // Note: phpThumb.php is where the caching code is located, if
  15  //   you instantiate your own phpThumb() object that code is
  16  //   bypassed and it's up to you to handle the reading and
  17  //   writing of cached files.
  18  
  19  
  20  
  21  require_once ('../phpthumb.class.php');
  22  
  23  // create 3 sizes of thumbnail
  24  $thumbnail_widths = array(160, 320, 640);
  25  foreach ($thumbnail_widths as $thumbnail_width) {
  26  
  27      // Note: If you want to loop through and create multiple
  28      //   thumbnails from different image sources, you should
  29      //   create and dispose an instance of phpThumb() each time
  30      //   through the loop and not reuse the object.
  31      $phpThumb = new phpThumb();
  32  
  33      // set data
  34      $phpThumb->setSourceFilename($_FILES['userfile']['tmp_name']);
  35      // or $phpThumb->setSourceData($binary_image_data);
  36      // or $phpThumb->setSourceImageResource($gd_image_resource);
  37  
  38      // set parameters (see "URL Parameters" in phpthumb.readme.txt)
  39      $phpThumb->setParameter('w', $thumbnail_width);
  40      //$phpThumb->setParameter('h', 100);
  41      //$phpThumb->setParameter('fltr', 'gam|1.2');
  42  
  43      // set options (see phpThumb.config.php)
  44      // here you must preface each option with "config_"
  45      $phpThumb->setParameter('config_output_format', 'jpeg');
  46      $phpThumb->setParameter('config_imagemagick_path', '/usr/local/bin/convert');
  47      //$phpThumb->setParameter('config_allow_src_above_docroot', true); // needed if you're working outside DOCUMENT_ROOT, in a temp dir for example
  48  
  49      // generate & output thumbnail
  50      $output_filename = './thumbnails/'.basename($_FILES['userfile']['name']).'_'.$thumbnail_width.'.'.$phpThumb->config_output_format;
  51      if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
  52          if ($output_filename) {
  53              if ($capture_raw_data && $phpThumb->RenderOutput()) {
  54                  // RenderOutput renders the thumbnail data to $phpThumb->outputImageData, not to a file or the browser
  55                  mysql_query("INSERT INTO `table` (`thumbnail`) VALUES ('".mysql_escape_string($phpThumb->outputImageData)."') WHERE (`id` = '".$id."');
  56              } elseif ($phpThumb->RenderToFile($output_filename)) {
  57                  // do something on success
  58                  echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
  59              } else {
  60                  // do something with debug/error messages
  61                  echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
  62              }
  63          } else {
  64              $phpThumb->OutputThumbnail();
  65          }
  66      } else {
  67          // do something with debug/error messages
  68          echo 'Failed (size='.$thumbnail_width.').<br>';
  69          echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">'.$phpThumb->fatalerror.'</div>';
  70          echo '<form><textarea rows="10" cols="60" wrap="off">'.htmlentities(implode("\n* ", $phpThumb->debugmessages)).'</textarea></form><hr>';
  71      }
  72  
  73      // remember to unset the object each time through the loop
  74      unset($phpThumb);
  75  }
  76  
  77  ?>


Generated: Mon Sep 8 04:35:41 2008 Cross-referenced by PHPXref 0.7