Пример #1
0
 /**
  * Returns an instance of self
  *
  * This is the usual singleton function that returns / instantiates the object
  *
  * @return JO_Phpthumb
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Пример #2
0
        $this->parentInstance = $that;
        $this->oldImage = $this->parentInstance->getOldImage();
        $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
        $this->workingImage = $this->parentInstance->getWorkingImage();
        $this->options = $this->parentInstance->getOptions();
        // make sure our arguments are valid
        if (!is_numeric($width)) {
            throw new InvalidArgumentException('$maxWidth must be numeric');
        }
        if (!is_numeric($height)) {
            throw new InvalidArgumentException('$maxHeight must be numeric');
        }
        // get the new dimensions...
        $this->newDimensions = array('newWidth' => $width, 'newHeight' => $height);
        // create the working image
        if (function_exists('imagecreatetruecolor')) {
            $this->workingImage = imagecreatetruecolor($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
        } else {
            $this->workingImage = imagecreate($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
        }
        //$this->parentInstance->preserveAlpha();
        // and create the newly sized image
        imagecopyresampled($this->workingImage, $this->oldImage, 0, 0, 0, 0, $this->newDimensions['newWidth'], $this->newDimensions['newHeight'], $this->currentDimensions['width'], $this->currentDimensions['height']);
        // update all the variables and resources to be correct
        $this->parentInstance->setOldImage($this->workingImage);
        $this->parentInstance->setCurrentDimensions($this->newDimensions);
        return $that;
    }
}
$pt = JO_Phpthumb::getInstance();
$pt->registerPlugin('JO_Phpthumb_Plugins_Gdcustombedita', 'gd');
Пример #3
0
 /**
  * Factory Function
  *
  * This function returns the correct thumbnail object, augmented with any appropriate plugins.
  * It does so by doing the following:
  *  - Getting an instance of PhpThumb
  *  - Loading plugins
  *  - Validating the default implemenation
  *  - Returning the desired default implementation if possible
  *  - Returning the GD implemenation if the default isn't available
  *  - Throwing an exception if no required libraries are present
  *
  * @return GdThumb
  * @uses PhpThumb
  * @param string $filename The path and file to load [optional]
  */
 public static function create($filename = null, $options = array(), $isDataStream = false)
 {
     self::$pluginPath = dirname(__FILE__) . '/Plugins/';
     // map our implementation to their class names
     $implementationMap = array('imagick' => 'JO_Phpthumb_Factory_Imagick', 'gd' => 'JO_Phpthumb_Factory_Gd');
     // grab an instance of PhpThumb
     $pt = JO_Phpthumb::getInstance();
     // load the plugins
     $pt->loadPlugins(self::$pluginPath);
     $toReturn = null;
     $implementation = self::$defaultImplemenation;
     // attempt to load the default implementation
     if ($pt->isValidImplementation(self::$defaultImplemenation)) {
         $imp = $implementationMap[self::$defaultImplemenation];
         $toReturn = new $imp($filename, $options, $isDataStream);
     } else {
         if ($pt->isValidImplementation('gd')) {
             $imp = $implementationMap['gd'];
             $implementation = 'gd';
             $toReturn = new $imp($filename, $options, $isDataStream);
         } else {
             throw new Exception('You must have either the GD or iMagick extension loaded to use this library');
         }
     }
     $registry = $pt->getPluginRegistry($implementation);
     $toReturn->importPlugins($registry);
     return $toReturn;
 }