We seem to be struggling to with Flysystem S3 and generating image styles for specific images with Flysystem S3.
We have been debugging this with both GD2 and Imagemagick libraries and both seem to struggle with the Flysystem S3. We are using PHP PHP Version 7.4.16 and GD 2.2.5.
The problem is that when a particular image is uploaded to S3, Drupal fails to generate a thumbnail or other image styles for it. If the image is run through an image processor (in this case pixlr.com), the image upload works and image styles are generated. I was originally suspecting that the problem is with the images and for example AdobeRGB color profile which the GD library might have problems with. But the same problematic image works fine in another environment where S3 is not used. Also when I change the image field to use public file storage instead of S3, the image starts to work and image styles are generated without errors.
There is an open issue also with Imagemagick where I was trying to debug if the problem is with the image library: https://www.drupal.org/project/imagemagick/issues/3129662. But it seems the problem might be more with the S3 module since the image styles are generated when the public storage is used.
I'll upload two test images here. The first one, test_image_original.jpg, does not work with S3 but works with pubiic file storage. The second one, test_image_processed.jpg, works with both.
I also noticed the following error in logs after trying to upload the problematic image:
Notice: Trying to access array offset on value of type bool in Twistor\StreamUtil::getSize() (line 93 of /var/www/html/builds/rsync/drupal/vendor/twistor/stream-util/src/StreamUtil.php). This might be related to the Imagemagick library issue where I noticed that the temporary file size was 0.
| Comment | File | Size | Author |
|---|---|---|---|
| test_image_processed.jpg | 340.22 KB | heikkiy | |
| test_image_original.jpg | 263.46 KB | heikkiy |
Comments
Comment #2
heikkiy commentedI also tested both the Drupal module and twistor/stream-util patches from the issue https://www.drupal.org/project/flysystem/issues/2661588. But the image styles are still not generating correctly for the problematic images.
With the patches in place the original image gets uploaded to S3 but the image styles are not generated. We also tested that it should not be a permission issue since the file object is completely missing from the bucket.
Comment #3
leon kessler commentedHaving the same issue here. Some images we are using fail to be resized, running through an image processor and re-uploading fixes the issue. I could also reproduce with the uploaded images on this ticket.
I tried to track down the issue, the furtherest I got was that
getimagesize()was returningFALSEfrom here: https://git.drupalcode.org/project/drupal/-/blob/9.3.x/core/modules/syst...I couldn't work out anything more from here, have tried looking at what happens within the league/flysystem-aws-s3-v3 twistor/flysystem-stream-wrapper and twistor/stream-util libraries, comparing this two when uploading an image that can and can't be resized, and also looking through their issue queues.
I also found that FlysystemStreamWrapper::stream_open() returns TRUE for both sets of images. And in my xdebug it appears that this is the function responsible for returning to
getimagesize()(although it gets a bit confusing as this is a core PHP function). So basically I don't quite know why or howgetimagesize()gets FALSE.