Commit 70961fa2 authored by Dmitriy Ivanov's avatar Dmitriy Ivanov Committed by Alex Moreno Lopez
Browse files

Issue #3239704 by shevchess: Breaks Drupal core "Convert" image style effect...

Issue #3239704 by shevchess: Breaks Drupal core "Convert" image style effect when converting an image to other extensions than .webp
parent 2cac1d61
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -131,9 +131,21 @@ class ImageStyleDownloadController extends FileDownloadController {

    // Don't try to generate file if source is missing.
    if (!file_exists($image_uri)) {
      // If the image style converted the extension, it has been added to the
      // original file, resulting in filenames like image.png.jpeg. So to find
      // the actual source image, we remove the extension and check if that
      // image exists.
      $path_info = pathinfo($this->streamWrapperManager->getTarget($image_uri));
      $converted_image_uri = sprintf('%s://%s%s%s', $this->streamWrapperManager->getScheme($image_uri), $path_info['dirname'], DIRECTORY_SEPARATOR, $path_info['filename']);
      if (!file_exists($converted_image_uri)) {
        $this->logger->notice('Source image at %source_image_path not found while trying to generate derivative image.', ['%source_image_path' => $image_uri]);
        return new Response($this->t('Error generating image, missing source file.'), 404);
      }
      else {
        // The converted file does exist, use it as the source.
        $image_uri = $converted_image_uri;
      }
    }

    // Check that the style is defined, the scheme is valid, and the image
    // derivative token is valid. Sites which require image derivatives to be