[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/editors/mostlyce/jscripts/tiny_mce/imagemanager/Classes/ -> Thumbnail.php (source)

   1  <?php
   2  /**

   3   * Create thumbnails.

   4   * @author $Author$

   5   * @version $Id$

   6   * @package ImageManager

   7   */
   8  
   9  
  10  require_once ('Transform.php');
  11  
  12  /**

  13   * Thumbnail creation

  14   * @author $Author$

  15   * @version $Id$

  16   * @package ImageManager

  17   * @subpackage Images

  18   */
  19  class Thumbnail 
  20  {
  21      /**

  22       * Graphics driver, GD, NetPBM or ImageMagick.

  23       */
  24      var $driver;
  25  
  26      /**

  27       * Thumbnail default width.

  28       */
  29      var $width = 96;
  30  
  31      /**

  32       * Thumbnail default height.

  33       */
  34      var $height = 96;
  35  
  36      /**

  37       * Thumbnail default JPEG quality.

  38       */
  39      var $quality = 85;
  40  
  41      /**

  42       * Thumbnail is proportional

  43       */
  44      var $proportional = true;
  45  
  46      /**

  47       * Default image type is JPEG.

  48       */
  49      var $type = 'jpeg';
  50  
  51      /**

  52       * Create a new Thumbnail instance.

  53       * @param int $width thumbnail width

  54       * @param int $height thumbnail height

  55       */
  56  	function Thumbnail($width=96, $height=96) 
  57      {
  58          $this->driver = Image_Transform::factory(IMAGE_CLASS);
  59          $this->width = $width;
  60          $this->height = $height;
  61      }
  62  
  63      /**

  64       * Create a thumbnail.

  65       * @param string $file the image for the thumbnail

  66       * @param string $thumbnail if not null, the thumbnail will be saved

  67       * as this parameter value.

  68       * @return boolean true if thumbnail is created, false otherwise

  69       */
  70  	function createThumbnail($file, $thumbnail=null) 
  71      {
  72          if(!is_file($file)) 
  73              Return false;
  74  
  75          //error_log('Creating Thumbs: '.$file);

  76  
  77          $this->driver->load($file);
  78  
  79          if($this->proportional) 
  80          {
  81              $width = $this->driver->img_x;
  82              $height = $this->driver->img_y;
  83  
  84              if ($width > $height)
  85                  $this->height = intval($this->width/$width*$height);
  86              else if ($height > $width)
  87                  $this->width = intval($this->height/$height*$width);
  88          }
  89  
  90          $this->driver->resize($this->width, $this->height);
  91  
  92          if(is_null($thumbnail)) 
  93              $this->save($file);
  94          else
  95              $this->save($thumbnail);
  96  
  97  
  98          $this->free();
  99  
 100          if(is_file($thumbnail)) 
 101              Return true;
 102          else
 103              Return false;
 104      }
 105  
 106      /**

 107       * Save the thumbnail file.

 108       * @param string $file file name to be saved as.

 109       */
 110  	function save($file) 
 111      {
 112          $this->driver->save($file);
 113      }
 114  
 115      /**

 116       * Free up the graphic driver resources.

 117       */
 118  	function free() 
 119      {
 120          $this->driver->free();
 121      }
 122  }
 123  
 124  
 125  ?>