diff options
| -rw-r--r-- | load_imagecache_presets.info | 5 | ||||
| -rw-r--r-- | load_imagecache_presets.install | 50 | ||||
| -rw-r--r-- | load_imagecache_presets.module | 135 | 
3 files changed, 190 insertions, 0 deletions
| diff --git a/load_imagecache_presets.info b/load_imagecache_presets.info new file mode 100644 index 0000000..20ac291 --- /dev/null +++ b/load_imagecache_presets.info @@ -0,0 +1,5 @@ +; $Id$ +name = "Load Image Cache Presets" +description = "Load a Set of Presets for modules using Imagecache " +core = 6.x +dependencies[] = imagecache diff --git a/load_imagecache_presets.install b/load_imagecache_presets.install new file mode 100644 index 0000000..9c88466 --- /dev/null +++ b/load_imagecache_presets.install @@ -0,0 +1,50 @@ +<?php +// $Id$ + +/** + * @file + * Banco de Conteudos Culturais Website installation procedures. + */ + +/** + * Includes. + */ +include_once('load_imagecache_presets.module'); + +/** + * Implementation of hook_install(). + * Install default cck. + */ +function load_imagecache_presets_install() { +  /** +   * The following code was replaced by using Features module. +   */ +  /* +  module_load_include('inc', 'install_profile_api', 'contrib/content_copy'); +  $files = file_scan_directory(drupal_get_path('module', 'bcc') .'/cck', '.*cck'); + +  foreach ($files as $file) { +    install_content_copy_import_from_file($file->filename); +  } +   */ + +  load_imagecache_presets_create(); +} + +/** + * Remove configuration data. + */ +function load_imagecache_presets_uninstall() { +  /** +   * Leave this commented out as it's better not to delete +   * cached data until we find a reason for that. +   */ +  /* +  $presets = imagecache_presets(); +  foreach ($presets as $options) { +    imagecache_preset_delete($options); +  } +   */ + +  // Remove variables +} diff --git a/load_imagecache_presets.module b/load_imagecache_presets.module new file mode 100644 index 0000000..e359d92 --- /dev/null +++ b/load_imagecache_presets.module @@ -0,0 +1,135 @@ +<?php +// $Id$ + +/** + * @file + * ImageCache functions. + */ + +/** + * Create ImageCache profiles for common display resolutions. + */ +function load_imagecache_presets_create() { +  $presets = module_invoke_all('load_imagecache_presets'); +  foreach ($presets as $options) { +    load_imagecache_preset_create($options); +  } +} + +/** + * Create an ImageCache preset. + * + * @param $options + *   Preset options. + * + * @see http://drupal.org/node/558664 + */ +function load_imagecache_preset_create($options) { +  // Set preset name +  if (isset($options['name'])) { +    $name = $options['name']; +  } +  else { +    $name = $options['width'] .'x'. $options['height']; +  } + +  // Check if preset already exists. +  $preset = imagecache_preset_by_name($name); +  if (!empty($preset)) { +    return; +  } + +  // Create a preset. +  $preset = imagecache_preset_save(array('presetname' => $name)); + +  // Set operation name. +  if (isset($options['action'])) { +    $operation = $options['action']; +  } +  else { +    $operation = 'imagecache_scale_and_crop'; +  } + +  // Add preset actions. +  $action           = new stdClass(); +  $action->presetid = $preset['presetid']; +  $action->module   = 'imagecache'; +  $action->action   = $operation; +  $action->data     = array('width' => $options['width'], 'height' => $options['height']); +  drupal_write_record('imagecache_action', $action); +} + +/** + * Delete an ImageCache preset. + * + * @param $options + *   Preset options. + */ +function load_imagecache_preset_delete($options) { +  // Set preset name. +  if (isset($options['name'])) { +    $name = $options['name']; +  } +  else { +    $name = $options['width'] .'x'. $options['height']; +  }     + +  // Check if preset exists. +  $preset = imagecache_preset_by_name($name); +  if (!empty($preset)) { +    imagecache_preset_delete(imagecache_preset_by_name($name)); +  } +} + +/** + * Update imagecache presets. + * + * @param $old + *   Old presets to be deleted. + * + * @param $new + *   New presets to be created. + */ +function load_imagecache_presets_update($old = array(), $new = NULL) { +  // Remove old presets. +  foreach ($old as $options) { +    load_imagecache_preset_delete($options); +  } + +  if ($new == NULL) { +    load_imagecache_presets_create(); +  } +  else { +    // Create new presets. +    foreach ($new as $options) { +      load_imagecache_preset_create($options); +    } +  } +} + +/** + * Return an array of common display resolutions. + */ +function load_imagecache_presets_load_imagecache_presets() { +  return array( +    array('width' => '90%', 'height' => '90%', 'operation' => 'imagecache_scale', 'name' => '0.90x0.90'), +    array('width' => '80%', 'height' => '80%', 'operation' => 'imagecache_scale', 'name' => '0.80x0.80'), +    array('width' => '70%', 'height' => '70%', 'operation' => 'imagecache_scale', 'name' => '0.70x0.70'), +    array('width' => '60%', 'height' => '60%', 'operation' => 'imagecache_scale', 'name' => '0.60x0.60'), +    array('width' => '50%', 'height' => '50%', 'operation' => 'imagecache_scale', 'name' => '0.50x0.50'), +    array('width' => '40%', 'height' => '40%', 'operation' => 'imagecache_scale', 'name' => '0.40x0.40'), +    array('width' => '30%', 'height' => '30%', 'operation' => 'imagecache_scale', 'name' => '0.30x0.30'), +    array('width' => '20%', 'height' => '20%', 'operation' => 'imagecache_scale', 'name' => '0.20x0.20'), +    array('width' => '10%', 'height' => '10%', 'operation' => 'imagecache_scale', 'name' => '0.10x0.10'), +    array('width' => '95%', 'height' => '95%', 'operation' => 'imagecache_scale', 'name' => '0.95x0.95'), +    array('width' => '85%', 'height' => '85%', 'operation' => 'imagecache_scale', 'name' => '0.85x0.85'), +    array('width' => '75%', 'height' => '75%', 'operation' => 'imagecache_scale', 'name' => '0.75x0.75'), +    array('width' => '65%', 'height' => '65%', 'operation' => 'imagecache_scale', 'name' => '0.65x0.65'), +    array('width' => '55%', 'height' => '55%', 'operation' => 'imagecache_scale', 'name' => '0.55x0.55'), +    array('width' => '45%', 'height' => '45%', 'operation' => 'imagecache_scale', 'name' => '0.45x0.45'), +    array('width' => '35%', 'height' => '35%', 'operation' => 'imagecache_scale', 'name' => '0.35x0.35'), +    array('width' => '25%', 'height' => '25%', 'operation' => 'imagecache_scale', 'name' => '0.25x0.25'), +    array('width' => '15%', 'height' => '15%', 'operation' => 'imagecache_scale', 'name' => '0.15x0.15'), +    array('width' => '5%',  'height' => '5%',  'operation' => 'imagecache_scale', 'name' => '0.05x0.05'), +  ); +} | 
