image_style_url

Versions
mediamosa-21
image_style_url($style_name, $path)

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

This function is the default image generation method. It returns a URL for an image that can be used in an <img> tag. When the browser requests the image at image/generate/[style_name]/[scheme]/[path] the image is generated if it does not already exist and then served to the browser. This allows each image to have its own PHP instance (and memory limit) for generation of the new image.

see image_style_generate()

Parameters

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

$path 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.

▾ 2 functions call image_style_url()

rdf_preprocess_field in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
theme_image_style in modules/image/image.module
Return a themed image using a specific image style.

Code

modules/image/image.module, line 730

<?php
function image_style_url($style_name, $path) {
  $destination = image_style_path($style_name, $path);

  // If the image already exists use that rather than regenerating it.
  if (file_exists($destination)) {
    return file_create_url($destination);
  }

  // Disable page cache for this request. This prevents anonymous users from
  // needlessly hitting the image generation URL when the image already exists.
  drupal_page_is_cacheable(FALSE);

  // Set a cache entry to grant access to this style/image path. This will be
  // checked by image_style_generate().
  cache_set('access:' . $style_name . ':' . md5($path), 1, 'cache_image', REQUEST_TIME + 600);

  $scheme = file_uri_scheme($path);
  $target = file_uri_target($path);

  // Generate a callback path for the image.
  $url = url('image/generate/' . $style_name . '/' . $scheme . '/' . $target, array('absolute' => TRUE));
  return $url;
}
?>