image_style_url

Versions
7
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.

▾ 1 function calls image_style_url()

theme_image_style in modules/image/image.module
Return a themed image using a specific image style.

Code

modules/image/image.module, line 734

<?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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.