By douglas.a.hatch on
In ImageCache, there is an option to run a custom action using PHP. I'd like a snippet of PHP which does the following:
1. Check the 'Authored On' date of the node.
2. If it's within the past 30 days, overlay image A.
3. If it's outside past 30 days, overlay image B.
This post may be of some use: http://drupal.org/node/325107
Upon successful execution of the code, I'll send payment by PayPal.
Comments
not that simple
the image_cache API provides the image to be modified and the action configuration data, but the related node isn't available, therefore a workaround should be found to "know" what node is being processed
workaround exists
That facility is provided by imagecache_actions - "Custom Action" which (I believe) is the harness being used here.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Solution Provided
For anyone interested, an excellent developer named Nauris provided the following solution:
With this code...
This is a run-once solution, but won;t solve the long-term requirements(?)
Note that because imagecache is a cache the image will not be re-generated with the update after the date has passed. Old images will still show up with the 'recent' overlay once they are built.
Unless you flush the cache entirely, nightly or something (bad idea).
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Yes, I've been mulling this
Yes, I've been mulling this over. My plan was to either manually, or on a cron, flush the entire cache for this preset each weekend. If you have a more elegant solution, I'd certainly be appreciative. Thanks!
Without thinking about it too
Without thinking about it too hard, I'd put it in the theme.
If (newish) render image with preset 'new', else render preset 'old'.
Would work fine, and actually be clearer code. Easier to find and maintain.
Returning a different image based on hidden information is creepy.
Thinking harder, a cronjob that just remakes images on nodes that are between 14 and 15 days old? Nah, creepy also.
This requirement falls outside of the scope of imagecache behaviour. Not a great path to go down.
Depending on requirements (?) I'd do something like that with a css overlay if all I wanted to do was flag a node image as 'new'. Inserting the class in the theme layer still.
.dan. is the New Zealand Drupal Developer working on Government Web Standards