Error retrieving images from styles that use ConvertImageEffect

Created on 5 October 2020, over 3 years ago
Updated 1 September 2023, 10 months ago

Problem/Motivation

Image styles that utilize core's ConvertImageEffect will change/append the image extension (for instance, source image of foo.jpeg may have a file extension of foo.jpeg.png in an image style that converts the type.)

Core's image module handles this like so:

    // 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($image_uri);
      $converted_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 at %derivative_path.', ['%source_image_path' => $image_uri, '%derivative_path' => $derivative_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;
      }
    }

Steps to reproduce

Add an image style that changes file type, and note the error generating the image on a local environment.

Proposed resolution

Adjust the FetchManager::fetch code to account for this scenario.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

🇺🇸United States jhedstrom Portland, OR

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024