thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.72k stars 2.67k forks source link

Unsupported image type image/heic. GD driver is only able to decode JPG, PNG, GIF, BMP or WebP files #5831

Open cotiga opened 5 months ago

cotiga commented 5 months ago

Laravel version

9.4

PHP version

8.2

Voyager version

1.6

Database

Mysql 8

Description

According to my research intervention/image in version 2 does not support the HEIC format. But version 3 does, by adding a portion of code. I wanted to know if it is possible to install version 3 and if it would work with Voyager?

Steps to reproduce

Upload an image from an iPhone

Expected behavior

I wanted to know if it is possible to install version 3 and if it would work with Voyager?

Screenshots

No response

Additional context

No response

Emerica commented 5 months ago

https://image.intervention.io/v3/introduction/upgrade

I'm going to say not directly, not without going over the upgrade guide and changing a bunch of methods/service provider, maybe caching. Things like encode() are used at the very least, but you'd have to search though and find if/what needs to be changed. https://github.com/thedevdojo/voyager/blob/7866a2d287c72b2682322d84f691974eb68c9331/src/Http/Controllers/ContentTypes/Image.php#L92C1-L95C92

cotiga commented 5 months ago

I'm working on it, will keep you informed

I found that :

https://github.com/Intervention/image/issues/1230

if ($file->getClientOriginalExtension() == 'heic') {
    $file = $request->file('image')
    $manager = new ImageManager(Driver::class);
    $image = $manager->read($file);
    $filename =  uniqid() . time() . rand(10, 1000000) . '.jpg';
    $image->toJpeg()->save('storage/images/'.$filename);
}
Emerica commented 5 months ago

This might be hacky, but you could potentially create middleware that would catch the upload request, Use https://github.com/MaestroError/php-heic-to-jpg and then pass the transformed jpg on.