使用 ImageCache 创建图像缩略图后如何使用 hook_nodeapi
上一个问题的后续内容。
正如我在该问题中提到的,我的总体目标是在 ImageCache 发挥其神奇作用并生成缩略图等之后调用 Ruby 脚本。
Sebi 在这个问题中的建议涉及使用 hook_nodeapi。
遗憾的是,我在创建模块和/或侵入现有模块方面的 Drupal 知识非常有限。
所以,对于这个问题:
- 我应该创建自己的模块还是尝试修改 ImageCache 模块?
- 如何将生成的缩略图路径(从 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:
- Should I create my own module or attempt to modify the ImageCache module?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要侵入 imagecache,记住每次你侵入 core/contrib 模块时上帝都会杀死一只小猫;)
您应该创建一个调用 hook_nodeapi 的模块,查看 api 文档以找到脚本的正确入口点,nodeapi 在节点进程的各个不同级别上工作,因此您必须为您选择正确的入口点(它当您查看链接时应该会变得清楚) http://api.drupal.org/api/ function/hook_nodeapi
您将无法调用您所显示的函数,因为它是私有的,因此您必须找到另一条路线。
您可以尝试手动构建路径,您应该能够提取上传文件的文件名,然后将其附加到目录结构中,虽然丑陋,但应该可以工作。例如,
如果上传的文件名为 test123.jpg 那么它应该位于 /files/imagecache/thumbnails/test123/jpg (或类似的文件)中。
希望有帮助。
Don't hack into imagecache, remember every time you hack core/contrib modules god kills a kitten ;)
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.