How to work with hook_nodeapi after image thumbnail creation with ImageCache

此生再无相见时 提交于 2019-12-25 04:43:32

问题


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.



来源:https://stackoverflow.com/questions/3635206/how-to-work-with-hook-nodeapi-after-image-thumbnail-creation-with-imagecache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!