Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ImageStyleDownloadController.php

function 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()
ImageHooks::fileDownload in core/modules/image/src/Hook/ImageHooks.php
Implements hook_file_download().
ImageStyleDownloadController::deliver in core/modules/image/src/Controller/ImageStyleDownloadController.php
Generates a derivative, given a style and image path.

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal