使用ImageCache创建图像缩略图后,如何使用hook_nodeapi [英] How to work with hook_nodeapi after image thumbnail creation with ImageCache

查看:127
本文介绍了使用ImageCache创建图像缩略图后,如何使用hook_nodeapi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前的问题的后续操作。

正如我在这个问题中提到的那样,我的整体目标是在ImageCache用魔术生成缩略图之后调用一个Ruby脚本。

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建议涉及使用hook_nodeapi。

可惜的是,我的Drupal对于创建模块和/或侵入现有模块的知识是非常有限的。

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.

所以,对于这个问题:


  1. 我应该创建自己的模块尝试修改ImageCache模块?

  2. 如何获取生成的缩略图路径(从ImageCache)传入我的Ruby脚本?






编辑

我发现这个< a href =https://stackoverflow.com/questions/2965490/generate-image-with-drupal-imagecache-before-using-imagecache-create-path-getim>问题通过SO搜索...
是否可以在 _imagecache_cache 函数中执行类似的操作,这样可以执行所需的操作?

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?

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. 不要侵入imagecache,记住每次你的核心/ contrib模块上帝杀死一只小猫;)

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

你应该创建一个模块调用hook_nodeapi,查看api文档,为您的脚本找到正确的入口点,nodeapi可以在各种不同级别的节点进程中工作,因此您必须为您选择正确的一个(当您检查链接时应该清楚) http://api.drupal.org/api/function/hook_nodeapi

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.

如果上传的文件被称为test123.jpg,那么它应该在/ files / imagecache / thumbnailails / test123 / jpg(或类似的东西)。

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

希望有帮助。

这篇关于使用ImageCache创建图像缩略图后,如何使用hook_nodeapi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆