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

x_magnet_x’s picture

Assigned: Unassigned » x_magnet_x
alan d.’s picture

Version: 6.x-1.6 »
Component: Code » Canvas Actions Module
Assigned: x_magnet_x » Unassigned

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.

alan d.’s picture

PS: A lazy way of doing a custom PHP action (10 is the imagecache preset id):

<?php
if ($preset = imagecache_preset(10)) {
  foreach ($preset['actions'] as $sub_action) {
    _imagecache_apply_action($sub_action, $image);
  }
}
return $image;
?>
alan d.’s picture

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;
}
?>
dman’s picture

Status: Active » Needs review
StatusFileSize
new241.05 KB
new3.29 KB

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!

alan d.’s picture

Cool, it has been useful addition on the last project we used.

Thanks for the module!

dman’s picture

Status: Needs review » Fixed

In -dev

Status: Fixed » Closed (fixed)
Issue tags: -imagecache, -preset action, -action on prior file

Automatically closed -- issue fixed for 2 weeks with no activity.