dimanche 12 juillet 2020

Error to save the uploaded favicon file with resize using Intervention package in Laravel 7.19.0

Intervention\Image\Exception\NotReadableException
Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.

Here is my code:

use Intervention\Image\ImageManagerStatic as Image;

$this->validate($request, [
                'logo' => 'image|mimes:jpeg,png,jpg',
                'favicon' => 'mimes:ico',
                'first_section_image' => 'image|mimes:jpeg,png,jpg'
               ]);

if ($request->hasFile('logo') || $request->hasFile('favicon') || $request->hasFile('first_section_image')) {

            if ($request->hasFile('logo')) {
                $image = $request->file('logo');
                $filename = $image->getClientOriginalName();
                $logoNameToStore = time() . "_" . $filename;

                $image_resize = Image::make($image->getRealPath());
                $image_resize->resize(46, 248);
                $image_resize->save(public_path('uploadedFiles/' . $logoNameToStore));
            }

            if ($request->hasFile('favicon')) {
                $image = $request->file('favicon');
                $filename = $image->getClientOriginalName();
                $faviconNameToStore = time() . "_" . $filename;

                $image_resize = Image::make($image->getRealPath());
                $image_resize->resize(16, 16);
                $image_resize->save(public_path('uploadedFiles/' . $faviconNameToStore));
            }

            if ($request->hasFile('first_section_image')) {
                $image = $request->file('first_section_image');
                $filename = $image->getClientOriginalName();
                $firstSectionImageNameToStore = time() . "_" . $filename;

                $image_resize = Image::make($image->getRealPath()); // <--- exception occurs here
                $image_resize->resize(1482, 1532);
                $image_resize->save(public_path('uploadedFiles/' . $firstSectionImageNameToStore));
            }

        }

I'm working on saving uploaded files by resizing. No problem faced with jpg, jpeg, png formats but facing issue with favicon file. If i'm not wrong then looks like that ico fomrat not supported to read & work by this package (like the other formats work). Is there any other way to do this using this package?

My goal is "Users will be allowed to upload any size favicon file. Laravel will grab the file and save the file in the directory by resizing to width: 16px & height: 16px".



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZnyEKg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire