Problem/Motivation

In some cases when in the flmngr or flmngr-cache folders exists broken files, after every image upload from the media library we will get the next warning
Warning: imagecreatefromstring(): Data is not in a recognized format in Drupal\n1ed\Flmngr\fs\CachedFile->getPreview() (line 132 of modules/contrib/n1ed/src/Flmngr/fs/CachedFile.php).
It happens because variable $contents which we pass into imagecreatefromstring($contents); could be empty.

Steps to reproduce

  1. open content entity edit page;
  2. attach existing image using media “Browse” button;
  3. scroll to the beginning of this field (if it has many images).

Proposed resolution

So I'm propose to check whether variable $contents empty or not before creating an image.
Patch with fix would be attached in the first comment.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

grapefruitjuice created an issue. See original summary.

grapefruitjuice’s picture

Here is the patch with my proposed fix

dmitriy-komarov’s picture

Sounds reasonable.
Thanks for the patch! We'll include it in the next update.