addPreset('galleriffic_thumbnail')->scaleAndCrop(75, 75); $h->addPreset('galleriffic_full')->scale(490, '', FALSE); $h->addPreset('frontpage')->scale(217, '', FALSE); $h->addPreset('imagesoverview_square')->scaleAndCrop(111, 111); $h->addPreset('map')->scale(400, '100%', FALSE); $h->addPreset('photo_thumb')->scale(100, 100, FALSE); } // ---------------------------------------- shortcut infrastructure ------------ /** * Implementation of hook_imagecache_default_presets() */ function example_imgcache_imagecache_default_presets() { $presets = array(); $hook_handler = new example_imgcache_HookHandler($presets); _example_imgcache_presets($hook_handler); return $presets; } class example_imgcache_HookHandler { protected $_presets; function __construct(&$presets) { $this->_presets = &$presets; } function addPreset($preset_name, array $settings = array()) { $this->_presets[$preset_name] = $settings + array( 'presetname' => $preset_name, 'actions' => array(), ); $preset = &$this->_presets[$preset_name]; return new example_imgcache_HookHandler_PresetWrapper($preset); } } class example_imgcache_HookHandler_PresetWrapper { protected $_preset; protected $_w; protected $_h; function __construct(array &$preset) { $this->_preset = &$preset; } /** * This one is generic, and accepts all kinds of actions */ function addAction($settings) { $this->_preset['actions'][] = $settings; return $this; } function scaleAndCrop($w, $h) { $this->_preset['actions'][] = array ( 'module' => 'imagecache', 'action' => 'imagecache_scale_and_crop', 'data' => array ( 'width' => $w, 'height' => $h, ), ); return $this; } function crop($w, $h) { $this->_preset['actions'][] = array ( 'module' => 'imagecache', 'action' => 'imagecache_crop', 'data' => array ( 'width' => $w, 'height' => $h, 'xoffset' => 'center', 'yoffset' => 'center', ), ); return $this; } function scale($w, $h, $upscale = TRUE) { $this->_preset['actions'][] = array ( 'module' => 'imagecache', 'action' => 'imagecache_scale', 'data' => array ( 'width' => $w, 'height' => $h, 'upscale' => $upscale ? 1 : 0, ), ); return $this; } }