diff options
Diffstat (limited to 'imagecache_auto.inc')
-rw-r--r-- | imagecache_auto.inc | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/imagecache_auto.inc b/imagecache_auto.inc deleted file mode 100644 index 78c5751..0000000 --- a/imagecache_auto.inc +++ /dev/null @@ -1,142 +0,0 @@ -<?php -/** - * @file - * ImageCache functions. - */ - -/** - * Create ImageCache profiles for common display resolutions. - */ -function imagecache_auto_create_presets() { - $presets = imagecache_auto_presets(); - foreach ($presets as $options) { - imagecache_auto_create_preset($options); - } -} - -/** - * Create an ImageCache preset. - * - * @param $options - * Preset options. - * - * @see http://drupal.org/node/558664 - */ -function imagecache_auto_create_preset($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; - } - - // Check if maximum number of presets was reached. - $max_presets = (int) variable_get('imagecache_auto_max_presets', '250'); - if (imagecache_auto_count_presets() + 1 > $max_presets) { - $message = 'Maximum number of imagecache presets reached. Please consider increasing the max number of presets.'; - watchdog('imagecache_auto', $message, array(), WATCHDOG_ERROR); - 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 imagecache_auto_delete_preset($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 imagecache_auto_presets_update($old = array(), $new = NULL) { - // Remove old presets. - foreach ($old as $options) { - imagecache_auto_delete_preset($options); - } - - if ($new == NULL) { - imagecache_auto_create_presets(); - } - else { - // Create new presets. - foreach ($new as $options) { - imagecache_auto_create_preset($options); - } - } -} - -/** - * Return an array of presets. - * - * @see http://en.wikipedia.org/wiki/List_of_common_resolutions - */ -function imagecache_auto_presets() { - $presets = array(); - foreach (module_implements('imagecache_auto_presets') as $module) { - $presets = array_merge($presets, module_invoke($module, 'imagecache_auto_presets')); - } - - return $presets; -} - -/** - * Count number of existing imagecache presets. - * - * @return - * Number of existing presets. - */ -function imagecache_auto_count_presets() { - $query = 'SELECT COUNT(presetid) AS count FROM {imagecache_preset}'; - $result = db_query($query); - $count = db_fetch_object($result); - return $count->count; -} - |