How to work with hook_nodeapi after image thumbnai

2019-09-11 11:25发布

问题:

A bit of a followup from a previous question.

As I mentioned in that question, my overall goal is to call a Ruby script after ImageCache does its magic with generating thumbnails and whatnot.

Sebi's suggestion from this question involved using hook_nodeapi.
Sadly, my Drupal knowledge of creating modules and/or hacking into existing modules is pretty limited.

So, for this question:

  1. Should I create my own module or attempt to modify the ImageCache module?
  2. How do I go about getting the generated thumbnail path (from ImageCache) to pass into my Ruby script?

edit

I found this question searching through SO... Is it possible to do something similar in the _imagecache_cache function that would do what I want?

ie

function _imagecache_cache($presetname, $path) {
  ...
  ...
  // check if deriv exists... (file was created between apaches request handler and reaching this code)
  // otherwise try to create the derivative.
  if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
    imagecache_transfer($dst);

    // call ruby script here
    call('MY RUBY SCRIPT');
  }

回答1:

  1. Don't hack into imagecache, remember every time you hack core/contrib modules god kills a kitten ;)

  2. You should create a module that invokes hook_nodeapi, look at the api documentation to find the correct entry point for your script, nodeapi works on various different levels of the node process so you have to pick the correct one for you (it should become clear when you check the link out) http://api.drupal.org/api/function/hook_nodeapi

You won't be able to call the function you've shown because it is private so you'll have to find another route.

You could try and build the path up manually, you should be able to pull out the filename of the uploaded file and then append it to the directory structure, ugly but it should work. e.g.

If the uploaded file is called test123.jpg then it should be in /files/imagecache/thumbnails/test123/jpg (or something similar).

Hope it helps.