Image derivative generation does not work if effect "Convert" in use and file stored in private filesystem

Created on 19 August 2016, almost 8 years ago
Updated 23 April 2024, 2 months ago

Problem/Motivation

If file is converted to another format, i.e. from jpg to gif, filepath does not match anymore. We already have a piece of code to match converted image uri but it works only for non-private files.

See Drupal\image\Controller\ImageStyleDownloadController::deliver():

    // 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.', array('%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;
      }
    }

Proposed resolution

  1. Wait for #2702227: Image styles for private files are serving the original instead of derivative
  2. Pass the correct image URI to the implementations of hook_file_download. The image URI should be one of the following:

Remaining tasks

as above

User interface changes

none

API changes

none

Data model changes

none

🐛 Bug report
Status

Fixed

Version

10.2

Component
Image system 

Last updated about 7 hours ago

Created by

🇳🇴Norway zaporylie

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

Merge Requests

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