You are here

function _image_filename in Image 7

Same name and namespace in other branches
  1. 5.2 image.module \_image_filename()
  2. 5 image.module \_image_filename()
  3. 6 image.module \_image_filename()

Creates an image filename.

Parameters

$filepath: The full path and filename of the original image file,relative to Drupal root, eg 'sites/default/files/images/myimage.jpg'.

Return value

A full path and filename with derivative image label inserted if required.

File

./image_legacy.module, line 47

Code

function _image_filename($filepath, $label = IMAGE_ORIGINAL, $temp = FALSE) {

  // Get default path for a new file.
  $path = file_directory_path() . '/' . variable_get('image_default_path', 'images');
  if ($temp) {
    $path .= '/temp';
  }
  $original_path = dirname($filepath);
  $filename = basename($filepath);
  if ($label && $label != IMAGE_ORIGINAL) {

    // Keep resized images in the same path, where original is (does not
    // apply to temporary files, these still use the default path).
    if (!$temp && $original_path != '.') {
      $path = $original_path;
    }

    // Insert the resized name in non-original images.
    $pos = strrpos($filename, '.');
    if ($pos === FALSE) {

      // The file had no extension - which happens in really old image.module
      // versions, so figure out the extension.
      $image_info = image_get_info(file_create_path($path . '/' . $filename));
      $filename = $filename . '.' . $label . '.' . $image_info['extension'];
    }
    else {
      $filename = substr($filename, 0, $pos) . '.' . $label . substr($filename, $pos);
    }
  }
  return file_create_path($path . '/' . $filename);
}