Ansel_ImageGenerator::factory PHP Method

factory() public static method

Horde_ImageGenerator factory
public static factory ( string $type, array $params = [] ) : Ansel_ImageGenerator
$type string The type of concrete instance to return.
$params array Additional parameters needed for the instance.
return Ansel_ImageGenerator
    public static function factory($type, $params = array())
    {
        $type = basename($type);
        $class = 'Ansel_ImageGenerator_' . $type;
        if (class_exists($class)) {
            $view = new $class($params);
            // Check that the image object supports what we need for the effect.
            foreach ($view->need as $need) {
                if (!Ansel::isAvailable($need)) {
                    $err = sprintf(_("This install does not support the %s feature. Please contact your administrator."), $need);
                    Horde::log($err, 'ERR');
                    throw new Ansel_Exception($err);
                }
            }
            return $view;
        } else {
            $err = sprintf(_("Unable to load the definition of %s."), $class);
            Horde::log($err, 'ERR');
            throw new Ansel_Exception($err);
        }
    }

Usage Example

Beispiel #1
0
 /**
  *
  * @return Horde_Image
  */
 protected function _create()
 {
     if ($GLOBALS['conf']['image']['squaremini']) {
         $generator = Ansel_ImageGenerator::factory('SquareThumb', array('width' => min(50, $this->_dimensions['width']), 'height' => min(50, $this->_dimensions['height']), 'image' => $this->_image, 'style' => $this->_params['style']));
         return $generator->create();
     } else {
         $this->_image->resize(min(50, $this->_dimensions['width']), min(50, $this->_dimensions['height']), true);
         if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) {
             try {
                 $this->_image->addEffect('Unsharpmask', array('radius' => $GLOBALS['conf']['thumbnail']['radius'], 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'], 'amount' => $GLOBALS['conf']['thumbnail']['amount']));
                 $this->_image->applyEffects();
             } catch (Horde_Image_Exception $e) {
                 throw new Ansel_Exception($e);
             }
         }
         return $this->_image->getHordeImage();
     }
 }
All Usage Examples Of Ansel_ImageGenerator::factory