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.
$path: The path to the image.
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.
function image_style_url($style_name, $path) {
$uri = image_style_path($style_name, $path);
// If not using clean URLs, the image derivative callback is only available
// with the script path. 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 ($GLOBALS['script_path'] && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
$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);
}