Hello everyone,
I have Image and Img_Assist installed on my 4.7 site and I am quite happy with the way they work together. However, I am concerned that the way Image files are currently being stored--all in the same directory--will become a major problem for me once we pass a threshold of several hundred images.
I did consider switching from Image to Acidfree, as it works with FileManager, but I'd rather not go this route as it does not work well with Img_Assist, and I don't really need the extra functionality it offers.
Ideally, I would like a separate folder set up within the files/images directory for each Image Gallery, but in lieu of that option, I would be satisfied with the functionality offered by FileManager, which is already installed on my site.
Has anyone out there gotten Image and Img_Assist to work with FileManager? Any patches, suggestions, or advice would be greatly appreciated!
Thanks much!!!!
Jon
Comments
Did you get any replies on this?
I'm looking into this. Did you get any replies? The problem is that file management in core is not so great. All files in a big directory doesn't really scale at all for large sites.
No, but...
Hello Schaub123!
Thanks for the response! No, I haven't had any other responses, which is pretty disappointing. I'm not expecting anyone to provide a full-blown solution, of course, just trying to wrap my head around the best path forward to fix this problem. On this note, I wish that there was a single point-of-entry for support requests/questions so that issues like this aren't simply overlooked....as it stands now, there are mailing lists, forums, etc., and it's unclear where to post to get the maximum possibility of someone who understands the issue to see it!
Anyway, my solution (for now) was to hack the image module. Basically, I updated the _image_filename function to take in the $node parameter, and then I use the $node variable to look for categories associated with that node. If I find a category, it checks for the existence of a folder with that category name in the files/images directory, and if it doesn't exist, it creates it, and saves the image under that directory.
This is certainly not an ideal solution for general purposes, but I believe it will work well for my own purposes. I will still be following up this forum topic to see if anyone else responds with a better way, but for now, my hack is working well.
Any chance of posting your code for this?
This would be a useful workaround for me too. Could you post your mods? Would be better of course if everything was under filemanager, but we don't live in a perfect world!
The code
OK, here are the relevant snippets of code I added to image.module to make this work. By the way, I am using category.module in place of the core taxonomy module, so this code will probably not work as-is if you are using core taxonomy.
Also, keep in mind that this is one of my first Drupal hacks, and as such, I am quite certain that this code can be optimized and improved upon. I'm almost embarrassed to post it, just b/c I dashed this off very quickly and, once it worked, didn't spend any time looking for a better way. I would request that anyone who sees a better way to do this would please post suggestions for improvements to the code.
That said, it does work, and for now, that's good enough for me.
1. First, add the $node parameter to the _image_filename function and adjust all references to this function in image.module to pass in $node accordingly. If you are running Img_Assist, there is a call to this function there which must be adjusted as well.
2. Add an else condition to the if ($temp) statement in _image_filename:
3. Add the full getCategoryDirectory function. It works, but are there better ways of doing this? (For example, I'm sure Drupal has its own "create directory" function, but I didn't have time to look for it, so I just used mkdir.) Also, keep in mind that if the node has multiple categories, this will only grab one of them.
4. Add the imagecat_cleanstring function. I borrowed most of this code from pathauto module. This will clean the category name of spaces and other bad characters.
Well, I guess that's it. I hope this helps someone else...and I also hope to get some feedback on improvements to this code.
Thanks very much for this! I
Thanks very much for this! I am actually using category module as well, but also organic groups so have decided to use the gid as a directory. Your code looks fine to me and was a very useful pointer at the mechanism of changing image... just one question, if your node has mulriple categories, the dir finally used will be the last one in the foreach loop, correct? If so I wonder how this changes when two nodes have multiple categories with only one common category. Equally with multi-language. I guess it doesn't really matter since the purpose is just to divide up the images from all being in one dir.
mkdir
FYI, the Drupal mkdir function appears to be file_check_directory in file.inc. You supply a path as the first parameter and FILE_CREATE_DIRECTORY as the second.
I am also trying to make the image module more friendly to lots of files. I'd like to store them by node number instead of the user's filename, but haven't got it working yet. Then I will split them into subdirectories by node ID in hundreds. So the first hundred image nodes will go in 0/, the next in 1/, etc.
Filemanager integration for the image, audio, and video modules would be welcome.
image.module that uses filemanager.module
I decided to tackle getting image.module to work with the filemanager.module. Here's what I came up with:
http://boonedocks.net/code/image.module.phps
Seems to work from limited testing, but I'd appreciate others giving it a try.
It requires an additional database table, and currently is hardcoded to only use the original, preview, and thumbnail sizes.
By the way, I haven't used img_assist, so I have not tried to integrate it.
My blog entry