Posted by x_magnet_x on October 30, 2009 at 10:28am
| Project: | ImageCache Actions |
| Component: | Canvas Actions Module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | action on prior file, imagecache, preset action |
Issue Summary
Hello,
I think it would be nice to have a Imagecache Action that called another Imagecache preset,
so that a sequence of generated files based on the prior file could be created.
A Sample: A cropped Thumbnail is created by a Imagecache preset, this preset hast at least a preset Action so you can generated a new file based on the prior preset with scale actions and so on!
Comments
#1
#2
Yep this would be a cool feature! We have a round corner effect on about 8 presets, it would be nice to do this in a single action (size and color underlay) and reference it all via a single preset.
#3
PS: A lazy way of doing a custom PHP action (10 is the imagecache preset id):
<?phpif ($preset = imagecache_preset(10)) {
foreach ($preset['actions'] as $sub_action) {
_imagecache_apply_action($sub_action, $image);
}
}
return $image;
?>
#4
And the code for the action:
<?php
function vsb_theme() {
return array(
'vsb_preset_reference' => array(
'arguments' => array('element' => NULL),
),
);
}
function vsb_imagecache_actions() {
$actions = array(
'vsb_preset_reference' => array(
'name' => 'Reference another preset',
'description' => 'Runs another defined preset on the image.',
),
);
return $actions;
}
function vsb_preset_reference_form($action) {
$action = (array)$action;
$form = array();
$presets = array();
foreach (imagecache_presets(TRUE) as $preset) {
$presets[$preset['presetid']] = $preset['presetname'];
}
$form['reference'] = array(
'#type' => 'select',
'#title' => t('Preset to use on the image'),
'#default_value' => $action['reference'],
'#options' => $presets,
);
return $form;
}
/**
* This lets the user see what parameters were selected for the action
*/
function theme_vsb_preset_reference($element) {
$data = $element['#value'];
if ($preset = imagecache_preset($data['reference'])) {
return t('%name (pid: !presetid)', array('%name' => $preset['presetname'], '!presetid' => $preset['presetid']));
}
return t('<span class="error">Invalid reference. The referenced preset has been deleted!</span>');
}
/**
* Prep the filter
*/
function vsb_preset_reference_image(&$image, $data) {
if ($preset = imagecache_preset($data['reference'])) {
foreach ($preset['actions'] as $sub_action) {
_imagecache_apply_action($sub_action, $image);
}
}
return true;
}
?>
#5
Hey, that looks like it might be working code!
Right, that makes so much sense I'll roll this in.
Now in 6.x-2-dev, as part of 'customactions'
... I renamed vsb_preset_reference to just 'subroutine'
Works for me!
Thanks for the contrib!
#6
Cool, it has been useful addition on the last project we used.
Thanks for the module!
#7
In -dev
#8
Automatically closed -- issue fixed for 2 weeks with no activity.