Since version 1.0.28 of Flysystem https://flysystem.thephpleague.com/v1/docs/adapter/aws-s3-v3/#streamed-r... they have enabled stream option by default. In certain cases it breaks image thumbnail generation.

Here's a small Drush script to demonstrate it:

<?php

$data_broken = getimagesize('spf://17.jpeg');

lando drush php-script testing.php

Lots of logs will be through about seek issues.

Use the same image I've attached and of course you have to use your own schema name.

For a quick fix, you can force the stream to false in vendor/league/flysystem-aws-s3-v3/src/AwsS3Adapter.php readObject() method.

Before:

        if ($this->streamReads && ! isset($options['@http']['stream'])) {
            $options['@http']['stream'] = true;
        }

After:

        if ($this->streamReads && ! isset($options['@http']['stream'])) {
            $options['@http']['stream'] = false;
        }

You shouldn't see any more errors.

Now the question is how to solve it without changing the stream setting globally? How could I switch it only where it breaks?

1 place in core where it breaks is at core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php parseFile() method. The same getimagesize() function fails silently.

Should I be extending the GDToolkit? Should be possible to create another @ImageToolkit annotated class?

CommentFileSizeAuthor
17.jpeg269.44 KBhkirsman

Comments

hkirsman created an issue. See original summary.

hkirsman’s picture

Title: How to fix getimagesize() calls? » How to fix PHP's getimagesize() calls?
hkirsman’s picture

We are bypassing Drupal when serving files to users so I thought I'd just disable streaming from settings:

      'options' => [
        '@http' => [
          'stream' => FALSE,
        ],
      ],
cupcakemuncher’s picture

I am not 100% sure, but I think this might be the cause for an error I observed.
Using images in media entites. The behavior is quite flaky.
Migrating 1000 images, to D9 i have observed that ~10% will not generate a thumbnail.
Looking at the files, the file-name, the alternative text, etc. yields not discernable result for the cause of this behavior.
Trying to manually upload the files in question by creating a new media entity, even when renamed, will result in the same outcome.
The thumbnail is not generated, but alternative text and title field are displayed.
Trying to save the entity will cause the error-message that values are not set.
The fields in question are hidden and concerned with the width and height of the image.

Version used is latest 2.x RC and D9.

leon kessler’s picture

cupcakemuncher’s picture

Hello Leon,

a bit hard for me to confirm right now as we switched packages, but I do not think so.
The referenced issue talks about actual file-data not data/fields describing the file.
Also, from their error-report, the issue seems to occur all the time for all data.
A fault in handling a stream context would not behave as flaky IMHO and the files were created on disk if I recall correctly.

Cheers

cupcakemuncher