You are here

protected function ImageStyle::addExtension in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/image/src/Entity/ImageStyle.php \Drupal\image\Entity\ImageStyle::addExtension()
  2. 9 core/modules/image/src/Entity/ImageStyle.php \Drupal\image\Entity\ImageStyle::addExtension()

Adds an extension to a path.

If this image style changes the extension of the derivative, this method adds the new extension to the given path. This way we avoid filename clashes while still allowing us to find the source image.

Parameters

string $path: The path to add the extension to.

Return value

string The given path if this image style doesn't change its extension, or the path with the added extension if it does.

2 calls to ImageStyle::addExtension()
ImageStyle::buildUri in core/modules/image/src/Entity/ImageStyle.php
Returns the URI of this image when using this style.
ImageStyle::getPathToken in core/modules/image/src/Entity/ImageStyle.php
Generates a token to protect an image style derivative.

File

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

Class

ImageStyle
Defines an image style configuration entity.

Namespace

Drupal\image\Entity

Code

protected function addExtension($path) {
  $original_extension = pathinfo($path, PATHINFO_EXTENSION);
  $extension = $this
    ->getDerivativeExtension($original_extension);
  if ($original_extension !== $extension) {
    $path .= '.' . $extension;
  }
  return $path;
}