In the imagecache process - the browser is requesting an image by name.
That's all that happens. It is a stateless, single, HTTP request.
The information available to the imagecache process is the image file name, and the preset name.
There is no context. We don't know what you were doing before the browser asked for the image, we don't know what you are going to do with that image.

Even if we were able to guess what your context was (from a cookie, session or referrer), the next time this filename is requested, you will get the previously cached one, no matter what your new context.
It's a cache, it deliberately does not build things on the fly if it can avoid it.

For this reason, if you want to pass arguments to your image, imagecache overall is not the right tool.

BUT, you would still be able to use imageAPI - and all the imagecache actions (and imagecache_actions) IF you were to build an image-generation harness that worked in a similar way to imagecache. Because of the way ImageAPI is abstracted, most of this is possible now. But that code does not yet exist AFAIK. Maybe it could be sponsored, it's a fun project.

But until then, no, you can't use imagecache_actions to build dynamic, time-or-context-sensitive images on the fly.

You can build data-sensitive images - where what happens to the image depends directly on the node or field that it's attached as - eg the text description or the taxonomy term it's been tagged with. And this is probably how you should look at doing things. But that's different from context or dynamic, made-up arguments.

Comments

mandreato’s picture


You can build data-sensitive images - where what happens to the image depends directly on the node or field that it's attached as - eg the text description or the taxonomy term it's been tagged with. And this is probably how you should look at doing things. But that's different from context or dynamic, made-up arguments.

So is it possible to apply an imagecache action on an image field of a node tagged with a specific term ?
For example: on a Ubercart products catalog, applying red corners on all products assigned to "promotion" vocabulary term.

Can you provide a little example of how to do that ?
Thanks In Advance.

dman’s picture

Data-driven actions are possible, though sometimes tricky.
Autorotate and textactions both do this. Textactions provides a get-node-from-image function that tries to look up the appropriate owning node and use data from it, eg to place the title as a caption or the date over the image.
So yes, this process could be used to choose one or the other image process based on tags. Though through php custom code, as a ui for all possible conditions would be too much.
I'm on holiday, so no code, but try drupal_set_message(print_r(get_defined_vars())). In the php custom code section. If a node is available as the 'owner' of the image, the Node object should be available for inspection. You'll have to flush the imagecache cache a lot.

As above, in this explanation, using this process will run once only, so flagging a node as "special" won't make the image display differently In real time, until you flush the image file cache some other way

mandreato’s picture

Thank you dman for bothering about this during holidays (which is no good ;-).
I've tried your suggestion:
- first I've activated TextAction module (however it was a bit unclear how to do it because I was using 6.x-2.x-dev and the release notes state textactions have gone to a new module but where is that new module ? So reverted to 6.x-1.x-dev...)
- then corrected a PHP 5.3 problem causing Parameter 1 to theme_imagecacheactions_rgb_form() expected to be a reference, value given in ...\includes\theme.inc on line 656 warning --> edited the function theme_imagecacheactions_rgb_form function of ...\sites\all\modules\imagecache_actions\utility.inc to remove the & from (&$form)
- overrided the product_list preset (which is an Ubercart preset used for product listing on catalog) to add a textactions_text2canvas action
- checked the "Evaluate text as PHP code" flag and put the following code:

foreach ($node->taxonomy as $term) {
  if ($term->name == 'NEW') {
    return 'NEW';
  }
}
return '';

As you predicted, the functionality was good as far as I flushed every time it was needed (i.e. add/remove the NEW term to/from a product).
So, the process is more clear now and we're nearer to the problem solution; but, how to overcome the flush issue ? Is there a way to automatically force the preset flush only for nodes whose taxonomy changes ?
Something that activates when I update a product (adding/removing the NEW category term) and flush just the images of that node (not the whole catalog).
Science fiction ?

dman’s picture

Well you've found the steps needed and understand the process, so that's all excellent.
There is currently no *tidy* process to trigger a cache flush based on content changes that I can do through the API. Withou being potentially horrifically inefficient. But if we can think of one it will happen eventually.
At this point I'd say do it through the theme layer, though that's not great either

Sorry about the textactions confusion. Yeah that's about trying to move some libraries around, then I had to move the get node data function back into the main module so it's still available for php code calls. Work in progress as you've found. Kudos for solving it your way.
That's about right.

We'll look for away to maybe get a better trigger for updates, but the cache feature of imagecache works against it

mandreato’s picture

Thank you again dman, I'll try the theming way 'till a more clean method is provided via ImageCache Actions. Maybe the core Trigger or the Rules modules could be used ? (ad advanced action to flush node image to assign to the node content insert/update).
...But now turn off the PC and go back to holidays ;-)

El Bandito’s picture

Hi Dman

I'm curious about this too. I would like to add an overlay image an image IF the node is flagged in some way ( taxonomy or CCK field ). Is there any reason why all actions are not data driven i.e. can be controlled by evaluating PHP code ?

Cheers and hope you enjoyed ( are enjoying your hols ),

El B