$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; }