function ImageStyleDownloadController::getUriWithoutConvertedExtension

Same name and namespace in other branches
  1. 11.x core/modules/image/src/Controller/ImageStyleDownloadController.php \Drupal\image\Controller\ImageStyleDownloadController::getUriWithoutConvertedExtension()

Get the file URI without the extension from any conversion image style.

If the image style converted the image, then an extension has been added to the original file, resulting in filenames like image.png.jpeg.

Parameters

string $uri: The file URI.

Return value

string The file URI without the extension from any conversion image style.

2 calls to ImageStyleDownloadController::getUriWithoutConvertedExtension()
ImageStyleDownloadController::deliver in core/modules/image/src/Controller/ImageStyleDownloadController.php
Generates a derivative, given a style and image path.
image_file_download in core/modules/image/image.module
Implements hook_file_download().

File

core/modules/image/src/Controller/ImageStyleDownloadController.php, line 300

Class

ImageStyleDownloadController
Defines a controller to serve image styles.

Namespace

Drupal\image\Controller

Code

public static function getUriWithoutConvertedExtension(string $uri) : string {
    $original_uri = $uri;
    $path_info = pathinfo(StreamWrapperManager::getTarget($uri));
    // Only convert the URI when the filename still has an extension.
    if (!empty($path_info['filename']) && pathinfo($path_info['filename'], PATHINFO_EXTENSION)) {
        $original_uri = StreamWrapperManager::getScheme($uri) . '://';
        if (!empty($path_info['dirname']) && $path_info['dirname'] !== '.') {
            $original_uri .= $path_info['dirname'] . DIRECTORY_SEPARATOR;
        }
        $original_uri .= $path_info['filename'];
    }
    return $original_uri;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.