You are here

function imagecache_create_url in ImageCache 5.2

Same name and namespace in other branches
  1. 6.2 imagecache.module \imagecache_create_url()

Return a URL that points to the location of a derivative of the original image transformed with the given preset.

Special care is taken to make this work with the possible combinations of Clean URLs and public/private downloads. For example, when Clean URLs are not available an URL with query should be returned, like http://example.com/?q=files/imagecache/foo.jpg, so that imagecache is able intercept the request for this file.

This code is very similar to the Drupal core function file_create_url(), but handles the case of Clean URLs and public downloads differently however.

Parameters

$presetname:

$filepath: String specifying the path to the image file.

$bypass_browser_cache: A Boolean indicating that the URL for the image should be distinct so that the visitors browser will not be able to use a previously cached version. This is

3 calls to imagecache_create_url()
imagecache_field_formatter in ./imagecache.module
Implementation of hook_field_formatter().
imagecache_ui_preset_form in ./imagecache_ui.module
theme_imagecache in ./imagecache.module
Create and image tag for an imagecache derivative

File

./imagecache.module, line 215
Dynamic image resizer and image cacher.

Code

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
  $path = _imagecache_strip_file_directory($filepath);
  if (module_exists('transliteration')) {
    $path = transliteration_get($path);
  }
  $query = empty($bypass_browser_cache) ? NULL : time();
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return url($GLOBALS['base_url'] . '/' . file_directory_path() . '/imagecache/' . $presetname . '/' . $path, $query, NULL, TRUE);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/imagecache/' . $presetname . '/' . $path, $query, NULL, TRUE);
  }
}