コード例 #1
0
 /**
  * Returns an instance of self
  * 
  * This is the usual singleton function that returns / instantiates the object
  * 
  * @return PhpThumbLatest
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #2
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 PhpThumbLatest
  *  - 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 PhpThumbLatest
  * @param string $filename The path and file to load [optional]
  */
 public static function create($filename = null, $options = array(), $isDataStream = false)
 {
     // map our implementation to their class names
     $implementationMap = array('imagick' => 'ImagickThumb', 'gd' => 'GdThumb');
     // grab an instance of PhpThumbLatest
     $pt = PhpThumbLatest::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;
 }
コード例 #3
0
                imagecopy($this->workingImage, $this->workingImage, $x, $y_i - $y - 1, $x, $y, 1, 1);
            }
        }
    }
    /**
     * Converts a hex color to rgb tuples
     * 
     * @return mixed 
     * @param string $hex
     * @param bool $asString
     */
    protected function hex2rgb($hex, $asString = false)
    {
        // strip off any leading #
        if (0 === strpos($hex, '#')) {
            $hex = substr($hex, 1);
        } elseif (0 === strpos($hex, '&H')) {
            $hex = substr($hex, 2);
        }
        // break into hex 3-tuple
        $cutpoint = ceil(strlen($hex) / 2) - 1;
        $rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);
        // convert each tuple to decimal
        $rgb[0] = isset($rgb[0]) ? hexdec($rgb[0]) : 0;
        $rgb[1] = isset($rgb[1]) ? hexdec($rgb[1]) : 0;
        $rgb[2] = isset($rgb[2]) ? hexdec($rgb[2]) : 0;
        return $asString ? "{$rgb[0]} {$rgb[1]} {$rgb[2]}" : $rgb;
    }
}
$pt = PhpThumbLatest::getInstance();
$pt->registerPlugin('GdReflectionLib', 'gd');