Using the following code:

print theme('imagecache', 'preset1', $field_pictures[$image_index]['filepath']);

... I can get an image with an applied preset directly ouput to the page.

What if I need only the path to that image, not the full themed output? What function can I call to get something like this:

http://www.myserver.com/sites/default/files/imagecache/preset1/1/c2.jpg

Comments

walker2238’s picture

Not sure if theres a better way but try adding your URL and apply the file name. so maybe try this...

print '<a href="/sites/default/files/imagecache/preset1/1/' . $field_pictures[0]['filename'] . '">My picture link</a>';
kirilius’s picture

Thanks, I figured something like that but I was hoping to be able to use an API function in order to stay independent on the actual physical paths.

walker2238’s picture

Forgive me is I don't understand you request very well. but you could also do...

print '<a href="/' . $field_image[0]['filepath']  . '">My picture link</a>';

Is that what you mean? If not I'm afraid I can't help you.

kirilius’s picture

Much like when you do the following functional call:

print theme('imagecache', 'preset1', $field_pictures[$image_index]['filepath']);

... you just pass the preset name as a parameter and don't care how the underlying file structure is organized...

I would like to call a function that hives me the physical path for an image derivative without the need to concatenate string literals myself.

walker2238’s picture

Okay I understand you now. I was actually looking to do the same thing awhile back and I couldn't find a solution. If you have any luck please let me know.

otsuarez’s picture

Status: Closed (fixed) » Active

Some sort of "workaround" would be using something like this:

<img src="/sites/default/files/imagecache/product-image/<?php  print basename($node->field_img[0]['filepath']); ?>">

where field_img is the cck field where the image is stored and product-image is the imagecache preset. For some reason, filename and filepath were different (maybe having to deal with me uploading more than one time the same image, the filepath had an extra _0 at the end of the filename).

Still, an api based function would be the ideal solution.

drewish’s picture

Status: Active » Fixed

imagecache_create_path() or imagecache_create_url() in imagecache.module.

kirilius’s picture

Thanks ;-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

NoRandom’s picture

Status: Active » Closed (fixed)

Just in case it helps to somebody. Using this method in Drupal 5 I had problems.

At first I had output link with this code:

$output = '< a href="/' . $imagecache_full . '" rel="lightbox" title="' . $node->title . '.">' . $imagecache_miniature . ''

Note the starting slash. This lead to double the base site in the url like h ttp://mysite.com//h ttp://mysite.com/files/foo/foo...

Removing the slash the generated url is ok.

Kind regards.