function _node_gallery_install_imagecache_presets in Node Gallery 6
Same name and namespace in other branches
- 6.2 node_gallery.install \_node_gallery_install_imagecache_presets()
2 calls to _node_gallery_install_imagecache_presets()
- node_gallery_install in ./
node_gallery.install - Implementation of hook_install()
- node_gallery_update_6100 in ./
node_gallery.install - Implementation of hook_update_N() Directly installing the default imagecache presets
File
- ./
node_gallery.install, line 204 - Node gallery install file.
Code
function _node_gallery_install_imagecache_presets() {
// First, build an array of all the preset names so we do not make duplicates
// Set the argument to TRUE to reset the cache
$presets = imagecache_presets(TRUE);
$preset_names = array();
//If there are any presets
if ($presets != '') {
foreach ($presets as $preset) {
$preset_names[] = $preset['presetname'];
}
}
// Prepare to install ImageCache presets
$imagecache_presets = array();
$imagecache_actions = array();
// We are checking to make sure the preset name does not exist before creating
if (!in_array('node-gallery-thumbnail', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-thumbnail',
);
$imagecache_actions['node-gallery-thumbnail'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 100,
'height' => 100,
),
'weight' => 0,
);
}
if (!in_array('node-gallery-cover', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-cover',
);
$imagecache_actions['node-gallery-cover'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 150,
'height' => 150,
),
'weight' => 0,
);
}
if (!in_array('node-gallery-display', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-display',
);
$imagecache_actions['node-gallery-display'][] = array(
'action' => 'imagecache_scale',
'data' => array(
'height' => 1500,
),
'weight' => 0,
);
$imagecache_actions['node-gallery-display'][] = array(
'action' => 'imagecache_scale',
'data' => array(
'width' => 600,
),
'weight' => 1,
);
}
// Need to install preset, id will be returned by function,
// Then install action add presetid to action prior to install:
foreach ($imagecache_presets as $preset) {
$preset = imagecache_preset_save($preset);
foreach ($imagecache_actions[$preset['presetname']] as $action) {
$action['presetid'] = $preset['presetid'];
imagecache_action_save($action);
}
drupal_set_message(t('ImageCache preset %id: %name and corresponding actions saved.', array(
'%id' => $preset['presetid'],
'%name' => $preset['presetname'],
)));
}
}