使用 ImageCache 创建图像缩略图后如何使用 hook_nodeapi

发布于 2024-09-18 01:48:57 字数 1065 浏览 2 评论 0原文

上一个问题的后续内容。

正如我在该问题中提到的,我的总体目标是在 ImageCache 发挥其神奇作用并生成缩略图等之后调用 Ruby 脚本。

Sebi 在这个问题中的建议涉及使用 hook_nodeapi。
遗憾的是,我在创建模块和/或侵入现有模块方面的 Drupal 知识非常有限。

所以,对于这个问题:

  1. 我应该创建自己的模块还是尝试修改 ImageCache 模块?
  2. 如何将生成的缩略图路径(从 ImageCache)传递到我的 Ruby 脚本中?

编辑

我发现了这个问题搜索SO... 是否可以在 _imagecache_cache 函数中执行类似的操作来实现我想要的功能?

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');
  }

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');
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

緦唸λ蓇 2024-09-25 01:48:57
  1. 不要侵入 imagecache,记住每次你侵入 core/contrib 模块时上帝都会杀死一只小猫;)

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

您将无法调用您所显示的函数,因为它是私有的,因此您必须找到另一条路线。

您可以尝试手动构建路径,您应该能够提取上传文件的文件名,然后将其附加到目录结构中,虽然丑陋,但应该可以工作。例如,

如果上传的文件名为 test123.jpg 那么它应该位于 /files/imagecache/thumbnails/test123/jpg (或类似的文件)中。

希望有帮助。

  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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文