If I'm going to be using imagecache for half of my images, I'd really prefer to use it for all of them, including images uploaded by the image module. Even though image.module does have its own derivatives, my theme templates are getting overly complicated and I prefer imagecache's derivatives anyway.
It was my understanding that all imagecache needed was a path to the original image file. So, for example, in my node-image.tpl.php shouldn't I be able to do something like this? :
<?php theme('imagecache', 'large', $node->images['_original'] ?>
Of course this doesn't work.
Comments
Comment #1
zach harkey commentedBelieve I may have answered my own question. It appears you just can't use the the imagecache theme functions.
This seems to work:
<img src="<?php file_create_url($node->images['_original']) ?>" alt="" />(I say 'seems to' because if past experience tells me anything it is that later today, i'll find a way to bork this.)
Comment #2
zach harkey commentedErrr. disregard last post, which completely left out the "imagecache/preset" part of the path and therefore wasn't dooing anything at all. The problem remains.
Comment #3
dopry commentedCan you give me the input and output of theme('imagecache',...)? It would really help with debugging your problem.
Comment #4
zach harkey commentedWait, I got it to work by using the theme_imagecache_display() function.
<?php print theme('imagecache_display', $node, 'thumbnail', file_create_url($node->images['_original']), array('class' => 'thumbnail')) ?>Is this the best way to achieve this? I'm still confused by the similiarities between theme_imagecache() and theme_imagecache_display().
Is there any problem with using imagecache to display all of my image.module images as well? (i.e. is it ok to replace all instances of image_display() with imagecache_display() in my node-image.tpl.php?)
Comment #5
dopry commentedtheme_imagecache_display was stolen directly from image.module while I was working on the theme_imagecache function. It expects a complete url to an image. You should probably not use it. It will disappear, and is identical to theme_image.
theme_imagecache is the function you should be using. Please provide the input and output to theme_imagecache for your particular situation. Otherwise I cannot help you further.
Comment #6
zach harkey commentedOk, here are some of the things I've tried. In each case, the first line is the code in my node-image.tpl.php, and the second line is the parsed output. Thanks very much for your help.
Comment #7
dopry commentedThe output of the first one would have been plenty...
Which version of drupal are you using and what is the CVS version of imagecache on the admin/imagecache page?
Is there a .htaccess file in sites, sites/staging.jadaloveless.com, or sites/staging.jadaloveless.com/files/ ?
Comment #8
zach harkey commentedSorry.
Drupal 4.7.4
imagecache.module,v 1.9.2.11
No, no, yes
The one in sites/staging.jadaloveless.com/files/ reads as follows:
Comment #9
zach harkey commentedOk, I've been experimenting off and on with different variations on this theme for the last week. Every once in while I am able to get imagecache to work in my image.tpl.php, but before I can actually figure out what I did to get it working, it stops working again.
For a while I was getting it to work as long as I uploaded images one at a time with the drupal form (node/add/image), but images uploaded with the image_pub.module weren't working. A short while later even these images weren't working.
For the record, I have the following line in image.tpl.php:
<?php print theme('imagecache', 'icon', $node->images['_original']) ?>which outputs the following html when parsed (e.g. node/65 )
<img src="http://example.com/sites/example.com/files/imagecache/icon/images/img-1454.jpg" alt="" />Unfortunately this produces a broken image icon since there is no image at this url.
However, if I remove the 'imagecache/icon/" portion of the url, the original image is perfectly accessible at its actual url (e.g. http://example.com/sites/example.com/files/images/img-1454.jpg).
Incidentally, it also produces the following errors in my apache log:
Is anyone else able to put a line like this in their image.tpl.php file and get it to work?
<?php print theme('imagecache', 'example_preset_name', $node->images['_original'] ?>Comment #10
zach harkey commentedInteresting development.
If I base my imagecache derivative off of the _original image, I get the errors mentioned in my last post, but if I use the default 'preview' derivative, created by image.module, everything works!?
In node-image.tpl.php this does not work:
<?php print theme('imagecache', 'icon', $node->images['_original']); ?>but this does:
<?php print theme('imagecache', 'icon', $node->images['preview']); ?>Comment #11
dopry commentedsounds like something else wrong might be happening... looking at the paths and URL's...
a request for http://example.com/sites/example.com/files/imagecache/icon/images/img-14....
will be looking for 'images/img-1454.jpg'.
that shouldn't result in imagecache looking for 'preview/images/img-1454.jpg'.
you should try reloading urls a couple of times and emptying your browser cache when reloading pages. You should also delete the imagecache tree between tests while initially configuring imagecache and check to see if your derivative image is generated each time you call the url.
Comment #12
zach harkey commentedI finally sorted this all out. Imagecache seems to work perfectly with images created by the image module.
In my particular case the problem was related to my using the php getimagesize() function in order to get the width x height of the image because I wanted it to display inside a containing
<li>element. Since the<li>is a block level element, and I wanted it to float, I had to specify a width to avoid browser bugs.Unfortunately, if the derivative had not yet been generated, as was often the case, then getimagesize() would fail and throw the above errors. Of course, this only becomes obvious when you do as dopry suggested and delete the entire imagecache directory between every test . This cannot be overstated.
The imagecache derivative is only created through the URL call,
file_create_path()won't do it, you have to usefile_create_url().Luckily
getimagesize()will accept a url instead of a file path, so for example, if I'm themeing a view that returns an array of image nodes: $nodes, I can do something like the following:Because my list items have specific width/height dimensions I can now use CSS to display the all the images inline.