Imagecache has become one of my favourite modules for Drupal and I'm using it in all my projects. There is one problem though. As the number of available actions increase I notice that the number of presets also increase. Here's a quick example why:
I develop a lot of online stores (with Übercart) and there's always a wish to visually tag product images with special information. In example on my latest project (online book store) I need to overlay small icons to indicate:
- If a product is on sale
- If a product is a physical or downloadable product.
- If there is a special preview (look inside the book)-function available on the product.
Since there are currently no conditions on actions I need to check for these 3 things in my templates and use the correct preset accordingly. This gives me a total of 9 presets for all the possible combinations. To make it worse, I have different sizes for the cart, search results, taxonomy listings and product view (product page view). This gives me a total of 36 presets. You get the idea?
If there only were a php-code condition field on every action with a node-object available we could use the same logic as with blocks. return true = execute the action, return false = ignore action. That way I would end up with a total of 4 presets instead of 36.
Have anyone worked on or discussed this previously? A quick search didn't give me much except some guy mentioning it in a comment on a Google Summer of Code project (IM Actions) but in a slightly different setting.
Any input / thoughts / patches / guidance on how to start implementing it would be greatly appreciated.
Have a nice day everyone.
Best regards,
Thomas Kulvik
Ny Media AS
www.nymedia.no
+47 920 28 082
Comments
Comment #1
drewish commentedwould need to happen in HEAD and then possibly be backported.
the problem is giving the action enough context to make a useful decision. imagecache doesn't know how the image is used or where so you'd have to create that context based solely on the filename.
have you tried writing your own action? i'd suggest giving that a try and then posting some results.
Comment #2
kulvik commentedI don't think that's a big problem. I've been using the gv_captions module for a while. this module provides a dynamic text action for images. It basically finds out which node a image is attached to and makes the node object available to the action. You can then configure the text by getting info from the node object itself.
This is the code being used to find the actual node:
However, I don't think we should be doing this in the actions themselves. It would be much better if this could be implemented in imagecache as a default behaviour for all actions. That way we won't have to rewrite every action available to imagecache.
I haven't looked into if this is possible (read: easy) or not but I bet some of you guys know that :)
Best regards,
Thomas Kulvik
Ny Media AS
www.nymedia.no
+47 920 28 082
Comment #3
drewish commentedthe problem is that the same file could be used in multiple contexts and imagecache can't know for certain which is which. actions can be implemented in other contrib modules so i'd rather seem some conditional actions developed there and tested on a variety of sites, and then look at adding them to imagecache.
Comment #4
fizk commentedAs per #3.