ImageStyle::buildUri

public ImageStyle::buildUri($uri)

Returns the URI of this image when using this style.

The path returned by this function may not exist. The default generation method only creates images when they are requested by a user's browser. Modules may implement this method to decide where to place derivatives.

Parameters

string $uri: The URI or path to the original image.

Return value

string The URI to the image derivative for this style.

Overrides ImageStyleInterface::buildUri

File

core/modules/image/src/Entity/ImageStyle.php, line 164

Class

ImageStyle
Defines an image style configuration entity.

Namespace

Drupal\image\Entity

Code

public function buildUri($uri) {
  $source_scheme = $scheme = $this->fileUriScheme($uri);
  $default_scheme = $this->fileDefaultScheme();

  if ($source_scheme) {
    $path = $this->fileUriTarget($uri);
    // The scheme of derivative image files only needs to be computed for
    // source files not stored in the default scheme.
    if ($source_scheme != $default_scheme) {
      $class = $this->getStreamWrapperManager()->getClass($source_scheme);
      $is_writable = $class::getType() & StreamWrapperInterface::WRITE;

      // Compute the derivative URI scheme. Derivatives created from writable
      // source stream wrappers will inherit the scheme. Derivatives created
      // from read-only stream wrappers will fall-back to the default scheme.
      $scheme = $is_writable ? $source_scheme : $default_scheme;
    }
  }
  else {
    $path = $uri;
    $source_scheme = $scheme = $default_scheme;
  }
  return "$scheme://styles/{$this->id()}/$source_scheme/{$this->addExtension($path)}";
}
doc_Drupal
2016-10-29 09:19:29
Comments
Leave a Comment

Please login to continue.