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

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


$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



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


function image_style_url($style_name, $uri) {
  if (image_is_svg($uri)) {
    return file_create_url($uri);
  $uri = image_style_path($style_name, $uri);
  $uri = file_uri_normalize_dot_segments($uri);

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

  // 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);