Reputation: 153
We are running are PHPUnit test in our Gitlab-CI. Every now and then some test are failing because of an exception:
Spatie\Image\Exceptions\CouldNotLoadImage: Could not load image at path `/builds/api/storage/media-library/temp/u9hn06FL7CIz4gDf3PClKfiCsP6CCNEn/eKb9zA0BzpXjZg1CDSityXjDUcewN0yfthumb-xs.jpeg`
/builds/api/vendor/spatie/image/src/Exceptions/CouldNotLoadImage.php:11
/builds/api/vendor/spatie/image/src/Drivers/Gd/GdDriver.php:92
/builds/api/vendor/spatie/image/src/Image.php:49
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/Actions/PerformManipulationsAction.php:34
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/Actions/PerformConversionAction.php:30
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/FileManipulator.php:71
/builds/api/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:240
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/FileManipulator.php:70
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/Jobs/PerformConversionsJob.php:30
/builds/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
/builds/api/vendor/laravel/framework/src/Illuminate/Container/Util.php:41
/builds/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
/builds/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35
/builds/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:662
/builds/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:128
/builds/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:144
/builds/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:119
/builds/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:132
/builds/api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:123
/builds/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:144
/builds/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:119
/builds/api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:122
/builds/api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:70
/builds/api/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:102
/builds/api/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php:43
/builds/api/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:59
/builds/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:247
/builds/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:230
/builds/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:77
/builds/api/vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingDispatch.php:193
/builds/api/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:388
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/FileManipulator.php:98
/builds/api/vendor/spatie/laravel-medialibrary/src/Conversions/FileManipulator.php:40
/builds/api/vendor/spatie/laravel-medialibrary/src/MediaCollections/Filesystem.php:37
/builds/api/vendor/spatie/laravel-medialibrary/src/MediaCollections/FileAdder.php:438
/builds/api/vendor/spatie/laravel-medialibrary/src/MediaCollections/FileAdder.php:420
/builds/api/vendor/spatie/laravel-medialibrary/src/MediaCollections/FileAdder.php:339
/builds/api/database/factories/ProjectPool/ProjectFactory.php:88
/builds/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:713
/builds/api/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:240
/builds/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:712
/builds/api/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:240
/builds/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:711
/builds/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:289
/builds/api/tests/Feature/API/Mutations/ProjectPool/UpdateProjectTest.php:107
It is always a different test-case which is failing and sometimes no test-case fails and our Pipeline succeeds. So it is not a reproducable error. Also when running the tests locally no error occurs.
We are using Minio both locally and in CI as our Laravel disk.
Media-Library-Version: v11.4.7
My guess is that when copying the file from S3/Minio to the local temp folder fails. But I cannot verify this, because the package does not check the success of copying these files...
Upvotes: 0
Views: 430
Reputation: 1
I had the same issue and it appeared that my php didn't support webp format. After enabling webp in php gd this problem disappeared.
Try to debug your path like this:
$path = 'your_path';
$handle = fopen($path, 'r');
$contents = fread($handle, filesize($path));
fclose($handle);
// in most cases exception will be trown here
// but in original code this line is suppressed with @
$image = imagecreatefromstring($contents);
Upvotes: -1
Reputation: 1
I would suggest trying imagick as the image driver to see if that changes anything.
You would have to enable imagick PHP extension. In .env you can specify the IMAGE_DRIVER, also take a look at media-library.image_driver.
I managed to get my media-library working with this change.
Edit: I got my Gd driver working by following this accepted answer. Call to undefined function Intervention\Image\Gd\imagecreatefromjpeg() Laravel 8 + Docker desktop 4.4.4
I was missing some of the Gd lib dependencies.
Upvotes: -1