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

arhak’s picture

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

dman’s picture

That facility is provided by imagecache_actions - "Custom Action" which (I believe) is the harness being used here.

douglas.a.hatch’s picture

For anyone interested, an excellent developer named Nauris provided the following solution:

$x = 5;
$y = 5;
$alpha = 100;
if ($node->created + 2592000 > time()) {
  $overlay = imageapi_image_open('/home/dougchunky/chunkybling-sandbox.com/sites/default/files/price_background.png');
} else
  $overlay = imageapi_image_open('/home/dougchunky/chunkybling-sandbox.com/sites/default/files/price_background3.png');
return imageapi_image_overlay($image, $overlay, $x, $y, $alpha );
dman’s picture

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).

douglas.a.hatch’s picture

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!

dman’s picture

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.