:) This was fun.

See attached illustrations for a quick idea.

Using the code image.module, I added a response to hook_image_alter - (which gets called for every _image_build_derivatives) so that the thumbnail (etc) building can be handed off to the imagecache pipeline!
Now, all thumbnails get resized, colour-shifted and decorated at create time.

I realize that I could have got similar results by over-riding the image_gallery.module themes in many places and redirected requests to an imagecache/path all the time, but that approach simply wasn't integrated enough with the way that the rest of Drupal works. It was much more sensible for me to change the thumbnail than to change (in all the various places it may be referenced) the path to it.

Also, this approach ties in pretty powerfully with the existing 'derivatives' menu that's already part of core.

CommentFileSizeAuthor
#1 image_imagecache_ui.png57.86 KBdman
construction_gallery.png175.26 KBdman

Comments

dman’s picture

StatusFileSize
new57.86 KB

Here's a snapshot of the UI

dman’s picture

And here's the relevant bit of the code.
Not a patch yet, as (my version of) the core is unstable pending a bit of collabaration.

Note, I've abstracted a nominal function imagecache_generate_image() which contains the meat of the do-everything function currently known as imagecache_cache()

It should be obvious what it does ;-).

I'm just throwing this 'issue' out there as a proof-of-concept for folk to look at. If we can work together to get the pending rewrite in then this can be added later. Or maybe it's overkill and I'm trying to pack too much utility into this module. I dunno.

/**
 * implimentation of hook_image_alter
 * 
 * Capture the image_build_derivatives phase and insert our own manipulations to
 * it any time an image is manipulated
 */
function imagecache_image_alter($node, $destination, $label) {
  $size = _image_get_dimensions($label);
  // Appended to the dimensions is our 'imagecache' id value. Maybe.
  if($presetid = $size['imagecache']){
    $original = file_create_path($node->images['_original']);
    $result = imagecache_generate_image($presetid, $original, $destination);
    # dsm("imagecache processed the $label through $preset to get '$result' ");
  }
}
/**
 * Add imagecache pipelining to the the image.module size derivatives form
 */
function imagecache_form_alter($form_id, &$form) {
  if($form_id == 'image_admin_settings'){
    // Sneak in our own little setting alongside the usual image dimensions
    $sizes = _image_get_sizes();
    $size_form = $form['sizes']['image_sizes'];
    $options = _imagecache_get_presets();
    $options = array(0=>"(no imagecache process)") + $options; // Unshift without re-indexing 

    foreach(element_children($size_form) as $key){
      $form['sizes']['image_sizes'][$key]['imagecache'] = array(
        '#type' => 'select',
        '#default_value' => $sizes[$key]['imagecache'],
        '#options' => $options,
      );
    }
    $form['sizes']['image_sizes']['#description'] .= t('<p> Optionally, choose an <a href="!imagecache_settings">imagecache preset</a> to use to generate this derivative image. The dimensions shown here are NOT used if you do this, so you may wish to include a resize into your imagecache preset instead.</p>', array('!imagecache_settings' => url('admin/settings/imagecache')));
  }
}

dopry’s picture

I've abstracted out imagecache_build_derivative and imagecache_apply_ action which should make it easier to integrate the two or build a glue module.

dman’s picture

sounds good. I'll see if I can revisit this sometime soon.
I've been meaning to have a look at the process abstractions to be able to contribute my other filters anyway. Seen in this eg is a transparency filter, a colour shift and an SVG rendering. (SVG may be a bit ambitious, but I'll run the other two up into callbacks for us)

Then see if this glue patch will still hold.

You see what fun it could be to run processes on our previews .... :-)

dopry’s picture

with D6 previews won't be a problem. yeah!

dopry’s picture

Status: Needs work » Closed (won't fix)

I'm leaving this integration to a glue module.