From 0b097f3d27109b1b6f52c4d21889f1d370006a22 Mon Sep 17 00:00:00 2001 From: Eric Kureck Date: Thu, 18 Nov 2010 15:29:31 -0200 Subject: first commit --- load_imagecache_presets.info | 5 ++ load_imagecache_presets.install | 50 +++++++++++++++ load_imagecache_presets.module | 135 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 load_imagecache_presets.info create mode 100644 load_imagecache_presets.install create mode 100644 load_imagecache_presets.module 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 @@ +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 @@ + $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'), + ); +} -- cgit v1.2.3