You are here

function imagecache_external_generate_path in Imagecache External 6.2

Same name and namespace in other branches
  1. 8 imagecache_external.module \imagecache_external_generate_path()
  2. 7.2 imagecache_external.module \imagecache_external_generate_path()
  3. 7 imagecache_external.module \imagecache_external_generate_path()

Util to generate a path to an image

Parameters

$url string the url to the image:

$preset imagecache preset:

Return value

string the url to the image

File

./imagecache_external.module, line 60

Code

function imagecache_external_generate_path($url, $preset) {
  $hash = md5($url);
  $dir = file_create_path('externals');
  if (!file_check_directory($dir)) {
    mkdir($dir, 0775, FALSE);
  }
  $hash = md5($url);
  $cachepath = file_create_path('externals/' . $hash);
  if (!is_file($cachepath)) {
    $result = imagecache_external_fetch($url, $cachepath);
    if (!$result) {

      //we couldn't get the file
      return FALSE;
    }
  }

  //we now have the file, return url relative to the imagecache preset
  return url(file_directory_path() . '/imagecache/' . $preset . '/externals/' . $hash);
}