Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297900

Generating jpg derivates of tif/tiff image files in public://

$
0
0

Problem/Motivation

We're dealing with a lot of image data in our module-kit WissKI (http://drupal.org/project/wisski/). While browsing the contents we found images missing since we switched on jpg derivative generation (image styles -> add convert jpg to any image style). At first I thought it is an imagemagick-problem and tried gm - but that did not help. The typical error message is like:

Source image at public://Gm117_01.tif.jpg not found while trying to generate derivative image at public://styles/x_/public/Gm117_01.tif.jpg.

I had a look at core/modules/image/src/Controller/ImageStyleDownloadController.php where this message comes from (line ~140). While debugging I found the problem - when using public://Gm117_01.tif.jpg the line

$converted_image_uri = $path_info['dirname'] . DIRECTORY_SEPARATOR . $path_info['filename'];

generates public:/Gm117_01.tif as its source. This however won't be found in the following line

if (!file_exists($converted_image_uri)) {

creating the error message above.

In case it is public:// or private:// we need two DIRECTORY_SEPARATOR .

Proposed resolution

For me I just fixed it like that:

// 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);
      if($path_info['dirname'] == "public:")
        $converted_image_uri = $path_info['dirname'] . DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR . $path_info['filename'];
      else
        $converted_image_uri = $path_info['dirname'] . DIRECTORY_SEPARATOR . $path_info['filename'];

However this does not cover private: and is not a good solution overall. However I do not have the knowledge to find a better one.

Remaining tasks

Build a better fix.


Viewing all articles
Browse latest Browse all 297900

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>