image_style_url

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 image_style_url($style_name, $path)

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.

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

See also

image_style_deliver()

▾ 8 functions call image_style_url()

ImageAdminStylesUnitTest::createSampleImage in modules/image/image.test
Given an image style, generate an image.
ImageAdminStylesUnitTest::testStyleReplacement in modules/image/image.test
Test deleting a style and choosing a replacement style.
ImageFieldDisplayTestCase::testImageFieldSettings in modules/image/image.test
Tests for image field settings.
ImageFieldDisplayTestCase::_testImageFieldFormatters in modules/image/image.test
Test image formatters on node display.
ImageStylesPathAndUrlUnitTest::_testImageStyleUrlAndPath in modules/image/image.test
Test image_style_url().
rdf_preprocess_field in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
theme_image_style in modules/image/image.module
Returns HTML for an image using a specific image style.
UserPictureTestCase::testWithGDinvalidDimension in modules/user/user.test
Do the test: GD Toolkit is installed Picture has invalid dimension

Code

modules/image/image.module, line 858

<?php
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 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 (!variable_get('clean_url') && 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);
}
?>