You are here

function image_resize_filter_pathinfo in Image Resize Filter 7

Same name and namespace in other branches
  1. 8 image_resize_filter.module \image_resize_filter_pathinfo()
  2. 6 image_resize_filter.module \image_resize_filter_pathinfo()

Utility function to return path information.

2 calls to image_resize_filter_pathinfo()
image_resize_filter_delete_derivatives in ./image_resize_filter.module
Delete all generated image when the original file is removed.
image_resize_filter_process_images in ./image_resize_filter.module
Processing function for image resize filter. Replace img src properties with a URL to a resized image.

File

./image_resize_filter.module, line 685
After adding to a text format, this filter will parse the contents of submitted content and automatically scale image files to match the set dimensions of img tags.

Code

function image_resize_filter_pathinfo($uri) {
  $info = pathinfo($uri);
  $info['extension'] = substr($uri, strrpos($uri, '.') + 1);
  $info['basename'] = drupal_basename($uri);
  $info['filename'] = drupal_basename($uri, '.' . $info['extension']);
  $info['scheme'] = file_uri_scheme($uri);

  // If scheme was empty, find stream wrapper with matching directory path.
  if (empty($info['scheme'])) {
    foreach (file_get_stream_wrappers() as $scheme => $stream_wrapper) {
      $scheme_base_path = file_stream_wrapper_get_instance_by_scheme($scheme)
        ->getDirectoryPath();
      if (empty($scheme_base_path)) {
        continue;
      }
      $matches = array();
      if (preg_match('/^' . preg_quote($scheme_base_path, '/') . '\\/?(.*)/', $info['dirname'], $matches)) {
        $info['scheme'] = $scheme;
        $info['dirname'] = $scheme . '://' . $matches[1];
        break;
      }
    }
  }

  // If scheme is still empty, fallback to public.
  if (empty($info['scheme'])) {
    $info['scheme'] = 'public';
  }
  return $info;
}