I tweaked this function to get it working on my system.... Changes:
- Added a function to create a path structure for the files if none exist
- Removed one of the mime_retrieval methods as it didn;t work for me - though a PNG was a text/plain!
Here is the "new" function...
function imagecache_cache() {
$generated = false;
$args = func_get_args();
$destination = file_create_path() . '/imagecache/' . implode('/', $args);
$dir = dirname($destination);
if(!file_check_directory($dir)) {
$folders = explode("/", $dir);
$path = array();
foreach($folders as $folder) {
$path[] = $folder;
if(!file_check_directory(implode("/", $path))) {
mkdir(implode("/", $path));
}
}
}
$function = array_shift($args);
switch ($function) {
case 'resize':
$width = array_shift($args);
$height = array_shift($args);
$source = file_create_path(implode('/', $args));
if (!is_file($source)) { echo '$source does not exist'; }
if (image_resize($source, $destination, $width, $height)) $generated = true;
break;
case 'scale':
$width = array_shift($args);
$height = array_shift($args);
$source = file_create_path(implode('/', $args));
if (!is_file($source)) { echo '$source does not exist'; }
if (image_scale($source, $destination, $width, $height)) $generated = true;
break;
}
if ($generated) {
$size = getimagesize($destination);
$mime = $size['mime'];
file_transfer($destination, array('Content-Type: ' . mime_header_encode($mime), 'Content-Length: ' . filesize($destination)));
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | imagecache.patch | 2.92 KB | nicholasthompson |
Comments
Comment #1
nicholasthompsonJust a follow up... I'm not sure why, but it seems to have lost quite a lot of its indentation! I can assue you, I dont code that way!!
Comment #2
dopry commentedCan you create a patch using diff? It makes it a lot easier for mesee exactly what changes you have made.
Comment #3
nicholasthompsonBelieve me - I'd love to! *goes off to look up how to use Diff...*
Comment #4
nicholasthompsonI have attached a patch file. Is this what you were looking for?
Comment #5
kindafun commentedI'd love to use this thing but I can't figure out how to do so. Have installed it, put this patch on it, but I don't see any sign of it anywhere. Haven't found any reference on how to use it anywhere either.
A little help?
Thanks!
Comment #6
nicholasthompsonAre you using it on its own or as part of something like CCK? On its own, you need to read the header of the module. You do something like:
/files/imagecache/[mode]/[width]/[height]/[path to file]
Comment #7
kindafun commentedThanks! I should have mentioned that I'm trying to use it with CCK. I did see the example function call, but with CCK is that necessary?
Comment #8
kindafun commentedOops again! I'm also using the imagefield with all the latest patches.
Comment #9
kindafun commentedI'm sorry about this, but maybe it will help someone coming later...
I can see that I can use this function in a CCK template file, is that it's intended use?
Comment #10
nicholasthompsonI had to tweak a theme template file for my CCK content type (eg, node-content-project.tpl.php... where project is my CCK node type).
From in there I had to something like this:
Ignore the image preview bit - that was a module I wrote myself which use a menu hook to pickup the imagepreview, then looked up the file by ID and generated a node with a screenshot in it... You'll be interesting in the image source bit.
Comment #11
kindafun commentedI appreciate your help here, but I still don't get it. It appears that this would result in something like the following output (exlcluding the anchor tag):
If I'm suppose to end up with a directory structure like that it's not happening.
Comment #12
dopry commentedI've applied the patch which provides the recursive mkdir, along with a major rewrite of imagecache.
Comment #13
marcoBauli commentedWhen i create my first ruleset and flush it, no directory path is automatically created, and i get the following warning:
Note: i am running Drupal 4.7.2 in multisite, latest imagecache v. 1.8.
Comment #14
marcoBauli commentedaha, thanks Dopry, i got bit better how it works now.
But i tryed inserting different possibilities of code in my Contemplate teaser:
.. still no image appears..
May Contemplate be the cause? or that no directory path was generated on first submission of the ruleset (see the note on the initial post)?
Comment #15
marcoBauli commentedops...sorry, #14 above has been posted on the wrong issue! :P
Comment #16
dopry commentedthe ruleset flush fails because the directory will not exist until a cached image is created. I'm setting back to fixed as the original recursive mkdir issue is closed. please do not open already closed issues for new bugs.
Comment #17
(not verified) commented