diff -u -p -r imagecrop.o/imagecrop.module imagecrop/imagecrop.module --- imagecrop.o/imagecrop.module Wed Mar 2 21:33:16 2011 +++ imagecrop/imagecrop.module Sun Mar 6 22:12:25 2011 @@ -54,6 +54,9 @@ function imagecrop_theme() { 'imagecrop_javascript' => array( 'arguments' => array('element' => NULL), ), + 'imagecrop_reuse' => array( + 'arguments' => array('element' => NULL), + ), 'imagecrop' => array( 'arguments' => array('url' => NULL, 'width' => NULL, 'height' => NULL, 'resize' => NULL), ), @@ -164,6 +167,11 @@ function imagecrop_imagecache_actions() 'imagecrop_javascript' => array( 'name' => 'Javascript crop', 'description' => 'Create a crop with a javascript toolbox.', + 'file' => 'imagecrop_actions.inc', + ), + 'imagecrop_reuse' => array( + 'name' => 'Javascript crop reuse selection', + 'description' => 'Reuse crop selection from another preset.', 'file' => 'imagecrop_actions.inc', ), ); diff -u -p -r imagecrop.o/imagecrop_actions.inc imagecrop/imagecrop_actions.inc --- imagecrop.o/imagecrop_actions.inc Wed Mar 2 21:33:16 2011 +++ imagecrop/imagecrop_actions.inc Sun Mar 6 22:11:17 2011 @@ -266,4 +266,41 @@ function imagecrop_match_requested_file_ return $image_dir == $search_directory; +} + +function imagecrop_reuse_form($data) { + $presets = imagecrop_presets_list(); + if (count($presets) > 0) { + $form['imagecrop_presetname'] = array( + '#title' => t('Enabled imagecrop presets'), + '#type' => 'select', + '#options' => $presets, + '#default_value' => (array) $data['imagecrop_presetname'], + ); + } + else { + $form['imagecrop_warning'] = array( + '#value' => t('No preset is found with the javascript_crop action so far. If you want to take advantage of this action, you will need to create at least one preset with javascript_crop action.'), + ); + } + return $form; +} + +function theme_imagecrop_reuse($element) { + $data = $element['#value']; + $description = $data['imagecrop_presetname']; + return $description; +} + +function imagecrop_reuse_image(&$image, $data) { + if ($preset_name = $data['imagecrop_presetname']) { + $preset = imagecache_preset_by_name($preset_name); + foreach ($preset['actions'] as $action) if($action['action'] == 'imagecrop_javascript') { + $GLOBALS['imagecrop_presetid'] = $preset['presetid']; + _imagecache_apply_action($action, $image); + return TRUE; + } + return FALSE; + } + return FALSE; }