spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Intervention\Image\Exception\NotReadableException: Unsupported image type application/x-empty. #3575

Closed TheROPFather closed 6 months ago

TheROPFather commented 7 months ago

I've been having this problem for a long time now.

This is what is shown in Horizon when investigating why the task failed

Intervention\Image\Exception\NotReadableException: Unsupported image type application/x-empty. GD driver is only able to decode JPG, PNG, GIF, BMP or WebP files. in

Stack trace shown below

#0 /var/www/website/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php(344): Intervention\Image\Gd\Decoder->initFromPath()
#1 /var/www/website/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(66): Intervention\Image\AbstractDecoder->init()
#2 /var/www/website/vendor/intervention/image/src/Intervention/Image/ImageManager.php(54): Intervention\Image\AbstractDriver->init()
#3 /var/www/website/vendor/league/glide/src/Api/Api.php(97): Intervention\Image\ImageManager->make()
#4 /var/www/website/vendor/league/glide/src/Server.php(689): League\Glide\Api\Api->run()
#5 /var/www/website/vendor/spatie/image/src/GlideConversion.php(72): League\Glide\Server->makeImage()
#6 /var/www/website/vendor/spatie/image/src/Image.php(120): Spatie\Image\GlideConversion->performManipulations()
#7 /var/www/website/vendor/spatie/laravel-medialibrary/src/Conversions/Actions/PerformManipulationsAction.php(33): Spatie\Image\Image->save()
#8 /var/www/website/vendor/spatie/laravel-medialibrary/src/Conversions/Actions/PerformConversionAction.php(30): Spatie\MediaLibrary\Conversions\Actions\PerformManipulationsAction->execute()
#9 /var/www/website/vendor/spatie/laravel-medialibrary/src/Conversions/FileManipulator.php(71): Spatie\MediaLibrary\Conversions\Actions\PerformConversionAction->execute()
#10 /var/www/website/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(240): Spatie\MediaLibrary\Conversions\FileManipulator->Spatie\MediaLibrary\Conversions\{closure}()
#11 /var/www/website/vendor/spatie/laravel-medialibrary/src/Conversions/FileManipulator.php(70): Illuminate\Support\Collection->each()
#12 /var/www/website/app/Jobs/PerformConversionsJob.php(25): Spatie\MediaLibrary\Conversions\FileManipulator->performConversions()
#13 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Jobs\PerformConversionsJob->handle()
#14 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#15 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#16 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#17 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
#18 /var/www/website/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
#19 /var/www/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#20 /var/www/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#21 /var/www/website/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#22 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(123): Illuminate\Bus\Dispatcher->dispatchNow()
#23 /var/www/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#24 /var/www/website/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#25 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
#26 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#27 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(102): Illuminate\Queue\CallQueuedHandler->call()
#28 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(439): Illuminate\Queue\Jobs\Job->fire()
#29 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(389): Illuminate\Queue\Worker->process()
#30 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(176): Illuminate\Queue\Worker->runJob()
#31 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(137): Illuminate\Queue\Worker->daemon()
#32 /var/www/website/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(120): Illuminate\Queue\Console\WorkCommand->runWorker()
#33 /var/www/website/vendor/laravel/horizon/src/Console/WorkCommand.php(51): Illuminate\Queue\Console\WorkCommand->handle()
#34 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Laravel\Horizon\Console\WorkCommand->handle()
#35 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#36 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#37 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#38 /var/www/website/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
#39 /var/www/website/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
#40 /var/www/website/vendor/symfony/console/Command/Command.php(326): Illuminate\Console\Command->execute()
#41 /var/www/website/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\Component\Console\Command\Command->run()
#42 /var/www/website/vendor/symfony/console/Application.php(1096): Illuminate\Console\Command->run()
#43 /var/www/website/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#44 /var/www/website/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#45 /var/www/website/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\Component\Console\Application->run()
#46 /var/www/website/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
#47 {main}

It appears to be complaining about the 7mai.png image.

"attributes":{
    "name":"7mai",
    "file_name":"7mai.png",
    "disk":"images",
    "conversions_disk":"images",
    "collection_name":"banner",
    "mime_type":"image/png",
    "size":64268,
    "custom_properties":"{"name":"banner"}",
    "generated_conversions":"[]",
    "responsive_images":"[]",
    "manipulations":"[]",
    "model_id":3227,
    "model_type":"App\Models\Resource",
    "uuid":"fc3d5624-6ecc-4997-b4e6-e2a0b3a9904b",
    "order_column":1,
    "updated_at":"2024-03-27 16:08:29",
    "created_at":"2024-03-27 16:08:29",
    "id":677793
},

The definition of the conversion is here

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('optimized')
            ->format(Manipulations::FORMAT_WEBP)
            ->withResponsiveImages();
    }

The webp file does get created, however the responsive images do not. The image is definitely a png, as evidenced here.

7mai.png: PNG image data, 256 x 80, 8-bit/color RGBA, non-interlaced

This is not the only image this happens with for me, this is just one example. I can provide hundreds more if needed.

I'm on the following versions

spatie/image                                  2.2.7     Manipulate images with an expressive API
spatie/image-optimizer                1.7.2     Easily optimize images using PHP

spatie/laravel-medialibrary         10.15.0   Associate files with Eloquent models
laravel/framework                         v10.47.0  The Laravel Framework.

And PHP 8.2.13.

I hope this is enough information, if not please just ask and I will do my best to accommodate.

TheROPFather commented 7 months ago

After doing some more investigating today I've discovered that this only appears to happen when the conversion and responsive image generation is on a queue.

When I use

   public function registerMediaCollections(Media $media = null): void
    {
        $this->addMediaCollection('banner')->singleFile()
            ->useDisk('images')
            ->useFallbackUrl(config('urls.frontend') . '/images/pack-fallback.png');
    }

    /**
     * @throws InvalidManipulation
     */
    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('optimized')
            ->format(Manipulations::FORMAT_WEBP)
           ->nonQueued()
            ->withResponsiveImages();
    }

Note the nonQueued() the error does not happen and everything is generated as it should be.

timvandijck commented 6 months ago

I happened to experience this bug myself and it was resolved after upgrading to v11. As this doesn't seem to be a problem in the latest version I'm going to close the issue for now. If anyone does happen to see this failing on v11 feel free to open an other issue so we can investigate.