1 image.module image_style_url($style_name, $uri)

Return the URL for an image derivative given a style and image path.

Parameters

$style_name: The name of the style to be used with this image.

$uri: The path to the image.

Return value

The absolute URL where a style image can be downloaded, suitable for use in an <img> tag. Requesting the URL will cause the image to be created.

See also

image_style_deliver()

File

core/modules/image/image.module, line 921
Exposes global functionality for creating image styles.

Code

function image_style_url($style_name, $uri) {
  $uri = image_style_path($style_name, $uri);

  $derivative_exists = file_exists($uri);
  if (!$derivative_exists) {
    image_style_add_allowed_uri($uri);
  }

  // If not using clean URLs, the image derivative callback is only available
  // with the query string. If the file does not exist, use url() to ensure
  // that it is included. Once the file exists it's fine to fall back to the
  // actual file path, this avoids bootstrapping PHP once the files are built.
  if (!config_get('system.core', 'clean_url') && file_uri_scheme($uri) == 'public' && !$derivative_exists) {
    $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
    return url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE));
  }

  return file_create_url($uri);
}